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__
效果图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值