4.1.7 实战 精灵类及其相关类的使用
2015-04-22 07:05
253 查看
部分代码源自SpriteTest.cpp中的Sprite1类的addNewSpriteWithCoords函数
void SpriteBatchNode1::addNewSpriteWithCoords(Vec2 p)
{
auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
//
随机产生精灵
int idx = CCRANDOM_0_1() * 1400 / 100;
int x = (idx%5) * 85;
int y = (idx/5) * 121;
//
创建精灵
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
BatchNode->addChild(sprite);
//
位置
sprite->setPosition( Vec2( p.x, p.y) );
//
创建动作
ActionInterval* action;
float random = CCRANDOM_0_1();
//
缩放
if( random < 0.20 )
action = ScaleBy::create(3, 2);
//
旋转
else if(random < 0.40)
action = RotateBy::create(3, 360);
//
闪烁
else if( random < 0.60)
action = Blink::create(1, 3);
//
else if( random < 0.8 )
action = TintBy::create(2, 0, -255, -255);
//
淡出
else
action = FadeOut::create(2);
auto action_back = action->reverse();
//
动作序列
auto seq = Sequence::create(action, action_back, nullptr);
//
运行动画
sprite->runAction( RepeatForever::create(seq));
}
void SpriteBatchNode1::addNewSpriteWithCoords(Vec2 p)
{
auto BatchNode = static_cast<SpriteBatchNode*>( getChildByTag(kTagSpriteBatchNode) );
//
随机产生精灵
int idx = CCRANDOM_0_1() * 1400 / 100;
int x = (idx%5) * 85;
int y = (idx/5) * 121;
//
创建精灵
auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121));
BatchNode->addChild(sprite);
//
位置
sprite->setPosition( Vec2( p.x, p.y) );
//
创建动作
ActionInterval* action;
float random = CCRANDOM_0_1();
//
缩放
if( random < 0.20 )
action = ScaleBy::create(3, 2);
//
旋转
else if(random < 0.40)
action = RotateBy::create(3, 360);
//
闪烁
else if( random < 0.60)
action = Blink::create(1, 3);
//
else if( random < 0.8 )
action = TintBy::create(2, 0, -255, -255);
//
淡出
else
action = FadeOut::create(2);
auto action_back = action->reverse();
//
动作序列
auto seq = Sequence::create(action, action_back, nullptr);
//
运行动画
sprite->runAction( RepeatForever::create(seq));
}
相关文章推荐
- ELK技术实战–了解Elk各组件 ELK技术实战-部署Elk 2.x平台 ELK Stack是软件集合Elasticsearch、Logstash、Kibana的简称,由这三个软件及其相关的组件可
- 黑马程序员---迭代器Iterator的使用及其相关方法
- 4000 iTerm2 的快捷键及其相关使用
- mybatis中获取SqlSessionFactory的几种方法及其相关使用
- VC控件DateTimePicker使用方法及其相关
- 】openssl移植Android使用及其相关经验分享
- JSF中使用dataScroller和dataTable实现分页及其相关问题
- Android学习指南之二十三:Drawable及其相关类的使用
- 【转】putty 及其相关工具 使用(pscp、psftp、plink)
- Scala深入浅出进阶经典 第61讲:Scala中隐式参数与隐式转换的联合使用实战详解及其在Spark中的应用源码解析
- Linux磁盘管理、文件系统相关知识点及其相关命令的使用方法
- 】openssl移植Android使用及其相关经验分享
- 在linux环境下安装Memcached及其简单使用+相关文档
- ios开发版证书与企业证书相关文件申请安装及其使用方法
- 】openssl移植Android使用及其相关经验分享
- iTerm2 的快捷键及其相关使用
- iOS开发中.pch 文件的使用及其相关工程设置
- 空间自相关及其SAM软件使用