ShowActionScene.h文件
#include<iostream>
#include<cocos2d.h>
USING_NS_CC;
class ShowAction :public Layer{
public:
static Scene* createScene();
virtual bool init();
CREATE_FUNC(ShowAction);
};
ShowActionScene.cpp文件
#include"ShowActionScene.h"
Scene* ShowAction::createScene(){
auto scene = Scene::create();
auto layer = ShowAction::create();
scene->addChild(layer);
return scene;
}
bool ShowAction::init(){
if (!Layer::init()){
return false;
}
//获得屏幕尺寸大小
Size visibleSize = Director::getInstance()->getVisibleSize();
//使用.png图片创建一个精灵
auto apple = Sprite::create("apple.png");
//设置精灵的位置在屏幕的正中
apple->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
//设置精灵不可见
apple->setVisible(false);
//将精灵添加到当前层的子节点
this->addChild(apple);
//创建一个show动作
auto show = Show::create();
//精灵执行show动作,精灵将会显示
apple->runAction(show);
//创建一个hide动作
auto hide = Hide::create();
//精灵执行hide动作,精灵将会隐藏
apple->runAction(hide);
//创建一个ToggleVisiblity动作
auto visibility = ToggleVisibility::create();
//ToggleVisibility动作切换节点的可见属性,择精灵又变成可见
apple->runAction(visibility);
//创建一个Blink动作,执行该动作的节点会在2秒内闪3次
auto blink = Blink::create(2, 3);
//精灵执行Blink动作
apple->runAction(blink);
return true;
}