zoukankan      html  css  js  c++  java
  • Cowboy实例

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

    cocos2d-x-2.2.2samplesCppTestCppResourcesarmature

    新建工程之后

    #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
    }
  • 相关阅读:
    编程题#2: 魔兽世界之二:装备
    程序设计实习MOOC / 继承和派生——编程作业 第五周程序填空题1
    【转】C++动态创建二维数组,二维数组指针
    HDU-2571命运
    HDU-1203 I NEED A OFFER!
    HDU-1003 Max Sum
    HDU2196-Computer
    HDU-1520 Anniversary party
    ChineseHelper(获取汉字字符串的首拼)
    车牌号正则表达式(新能源车牌)
  • 原文地址:https://www.cnblogs.com/newlist/p/3557609.html
Copyright © 2011-2022 走看看