cocos2d-x 3.x学习之ActionCombination

#include<iostream>
#include<cocos2d.h>
USING_NS_CC;
class ActionCombination :public Layer{
public:
	static Scene* createScene();
	virtual bool init();
	void menuCloseCallback(cocos2d::Ref* pSender);
	CREATE_FUNC(ActionCombination);
};
Sequence动作和Spawn动作的区别是前者按顺序执行,后者同时执行多个动作。
#include "ActionCombination.h"
Scene* ActionCombination::createScene(){
    auto scene = Scene::create();
	auto layer = ActionCombination::create();
	scene->addChild(layer);
	return scene;
}

bool ActionCombination::init(){
	if (!Layer::init()){
		return false;
	}
    Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();
	auto closeItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
		CC_CALLBACK_1(ActionCombination::menuCloseCallback, this));

	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
		origin.y + closeItem->getContentSize().height / 2));
	auto menu = Menu::create(closeItem, NULL);
	menu->setPosition(Point::ZERO);
	this->addChild(menu, 1);
    //创建一个精灵在左边,用于测试sequence组合动作
	auto left = Sprite::create("dance.png");
	left->setPosition(Point(visibleSize.width / 2 - 200, visibleSize.height / 2));
	this->addChild(left);
	//定义第一个RotateTo动作,旋转45度
	auto rotateTo1 = RotateTo::create(5, 45);
	//定义第一个RotateTo动作,旋转90度
	auto rotateTo2 = RotateTo::create(5, 90);
	//注意,是按顺序执行2个动作
	left->runAction(Sequence::create(rotateTo1, rotateTo2, NULL));
    //右边
	auto right = Sprite::create("dance.png");
	right->setPosition(Point(visibleSize.width / 2 + 200, visibleSize.height / 2));
	auto rotateTo3 = RotateTo::create(5, 45);
	auto rotateTo4 = RotateTo::create(5, 90);
	right->runAction(Spawn::create(rotateTo3, rotateTo4, NULL));

	return true;
}
void ActionCombination::menuCloseCallback(Ref* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
	MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert");
	return;
#endif

	Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	exit(0);
#endif
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值