zoukankan      html  css  js  c++  java
  • hero的动作效果

    .cpp文件

    #include "HelloWorldScene.h"
    
    USING_NS_CC;
    USING_NS_CC_EXT;
    
    Scene* HelloWorld::createScene()
    {
        // 'scene' is an autorelease object
        Scene *scene = Scene::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 ( !Layer::init())
        {
            return false;
        }
        
        Size screenSize = Director::getInstance()->getWinSize();
        
        Sprite *bg = Sprite::create("background.png");
        bg->setPosition(Point(screenSize.width/2, screenSize.height/2));
        addChild(bg);
    	
        hero = Sprite::create("hero.png");
        hero->setPosition(Point(screenSize.width/2, screenSize.height/2));
        addChild(hero);
        
        MenuItemFont *itemFlipX = MenuItemFont::create("FlipX",CC_CALLBACK_1(HelloWorld::testFlipX, this));
        itemFlipX->setPosition(Point(100, 50));
        MenuItemFont *itemFlipY = MenuItemFont::create("FlipY",CC_CALLBACK_1(HelloWorld::testFlipY, this));
        itemFlipY->setPosition(Point(200, 50));
        MenuItemFont *itemHide = MenuItemFont::create("Hide",CC_CALLBACK_1(HelloWorld::testHide, this));
        itemHide->setPosition(Point(300, 50));
        MenuItemFont *itemShow = MenuItemFont::create("Show",CC_CALLBACK_1(HelloWorld::testShow, this));
        itemShow->setPosition(Point(400, 50));
        
        Menu *actionMenu = Menu::create(itemFlipX,itemFlipY,itemHide,itemShow,NULL);
        actionMenu->setPosition(Point(0,0));
        addChild(actionMenu);
        
        return true;
        
    }
    
    
    HelloWorld::~HelloWorld(){
    	CC_SAFE_RELEASE(hero);
    }
    
    void HelloWorld::testFlipX(Object* sender)
    {
        if (hero->isFlipX()) {
            hero->runAction(FlipX::create(false));
        }else{
            hero->runAction(FlipX::create(true));
        }
    }
    void HelloWorld::testFlipY(Object* sender)
    {
        if (hero->isFlipY()) {
            hero->runAction(FlipY::create(false));
        }else{
            hero->runAction(FlipY::create(true));
        }
        
    }
    void HelloWorld::testShow(Object* sender)
    {
        hero->runAction(Show::create());
    }
    void HelloWorld::testHide(Object* sender)
    {
        hero->runAction(Hide::create());
    }
    
    
    
    
    .h文件

    #ifndef __HELLOWORLD_SCENE_H__
    #define __HELLOWORLD_SCENE_H__
    
    #include "cocos2d.h"
    #include "cocos-ext.h"
    USING_NS_CC;
    USING_NS_CC_EXT;
    class HelloWorld :public Layer
    {
        Sprite *hero ;
    public:
        // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
        virtual bool init();  
    	~HelloWorld();
        // there's no 'id' in cpp, so we recommend returning the class instance pointer
        //static Scene* scene();
    	static cocos2d::Scene* createScene();
        CREATE_FUNC(HelloWorld);
        
        EditBox *_editName;
        EditBox* _editPassword;
        
        void testFlipX(Object* sender);
        void testFlipY(Object* sender);
        void testHide(Object* sender);
        void testShow(Object* sender);
    };
    
    #endif // __HELLOWORLD_SCENE_H__
    效果图:



  • 相关阅读:
    如何查看存储过程中动态生成的sql
    [原] 高淇Java300集系列笔记 (待续)
    [原] 在HTML文档中添加标签名、ID、类名
    jquery学习笔记1-Ajax跨站请求资源
    博客搬家啦。请访问我的新底盘www.boyipark.com
    web端跨域调用webapi
    遮罩层
    去掉字符串后最后一个 ","
    对JAVA的static深刻理解(结合C语言的思考)
    java事件响应方法汇总(容器类监听、监听器类、AbstractAction、反射)
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091877.html
Copyright © 2011-2022 走看看