newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

这个例子主要是用cocos2d-x引擎自带的资源

cocos2d-x-2.2.2\samples\Cpp\TestCpp\Resources\armature

新建工程之后

 

#include "HelloWorldScene.h"
#include "cocos-ext.h"

USING_NS_CC;
USING_NS_CC_EXT;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCArmatureDataManager::sharedArmatureDataManager()->
        addArmatureFileInfo("armature\\Cowboy0.png", "armature\\Cowboy0.plist", "armature\\Cowboy.ExportJson");
//主要是这里的名字要跟ExportJson的一样
    CCArmature* pArm = CCArmature::create("Cowboy");
    pArm->getAnimation()->playByIndex(0);

    pArm->getAnimation()->setSpeedScale(1);

    pArm->setScaleX(-0.2f);
    pArm->setScaleY(0.2f);
    pArm->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2,
        CCDirector::sharedDirector()->getWinSize().height / 2));
    this->addChild(pArm);

    return true;
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
    CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
    CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
#endif
}

 

posted on 2014-02-20 14:34  一枚程序  阅读(336)  评论(0编辑  收藏  举报