bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto s = Director::getInstance()->getWinSize(); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("grossini.plist");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("grossini-generic.plist"); auto layer1 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
layer1->setPosition(Point(s.width/2-80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
addChild(layer1); sprite1 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_01.png"));
sprite1->setPosition(Point( s.width/2-80, s.height/2));
addChild(sprite1); sprite1->setFlippedX(false);
sprite1->setFlippedY(false); auto layer2 = LayerColor::create(Color4B(255, 0, 0, 255), 85, 121);
layer2->setPosition(Point(s.width/2+80 - (85.0f * 0.5f), s.height/2 - (121.0f * 0.5f)));
addChild(layer2); sprite2 = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_generic_01.png"));
sprite2->setPosition(Point( s.width/2 + 80, s.height/2));
addChild(sprite2); sprite2->setFlippedX(false);
sprite2->setFlippedY(false); schedule(schedule_selector(HelloWorld::startIn05Secs), 1.0f); sprite1->retain();
sprite2->retain(); counter = 0; return true;
} void HelloWorld::startIn05Secs(float dt)
{
unschedule(schedule_selector(HelloWorld::startIn05Secs));
schedule(schedule_selector(HelloWorld::flipSprites), 0.5f);
} static int spriteFrameIndex = 0;
void HelloWorld::flipSprites(float dt)
{
counter++; bool fx = false;
bool fy = false;
int i = counter % 4; switch ( i )
{
case 0:
fx = false;
fy = false;
break;
case 1:
fx = true;
fy = false;
break;
case 2:
fx = false;
fy = true;
break;
case 3:
fx = true;
fy = true;
break;
} sprite1->setFlippedX(fx);
sprite2->setFlippedX(fx);
sprite1->setFlippedY(fy);
sprite2->setFlippedY(fy); if(++spriteFrameIndex > 14)
{
spriteFrameIndex = 1;
} char str1[32] = {0};
char str2[32] = {0};
sprintf(str1, "grossini_dance_%02d.png", spriteFrameIndex);
sprintf(str2, "grossini_dance_generic_%02d.png", spriteFrameIndex);
sprite1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str1));
sprite2->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str2));
}

cocos2d-x3.0 SpriteFrameCache的更多相关文章

  1. 如何在Cocos2D 1.0 中掩饰一个精灵(六)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 掩饰一个精灵:实现代码 打开HelloWorldLayer.m并 ...

  2. 如何在Cocos2D 1.0 中掩饰一个精灵(一)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 原帖来自Ray Wunderlich写的精彩的文章 How To ...

  3. Cocos2D v2.0至v3.x简洁转换指南(三)

    Cocos2D 3.3中的注意事项 如果你在使用Cocos2D 3.3+(是SpriteBuilder 1.3+的一部分)你将不得不替分别的换所有存在的UITouch和UITouchEvent为CCT ...

  4. Cocos2D v2.0至v3.x简洁转换指南(二)

    触摸处理 我们在稍后将完成Cocos2d 3.0中触摸处理的完整教程.而现在最重要的是知道如何去启用触摸处理在你的CCNode中: self.userInteractionEnabled = TRUE ...

  5. 如何将各种低版本的discuz版本升级到discuz x3.0

    最近在做discuz改版的项目,遇到了很多问题,相信很多拥有discuz论坛的版主,站长和程序猿在升级或改版discuz的过程中遇到过和我一样的问题,所以我开了一个discuz专栏,为大家讲解一下di ...

  6. cocos2d 2.0和UIKit混合编程, Push CCDirector的时候出现黑屏的天坑

    症状 使用cocos2d 2.0和UIKit混合编程, 有一块用cocos2d编写的小程序, 将CCDirector push到一个UINavigationController里面. 虽然事先在后台初 ...

  7. cocos2d-x3.0创建第一个jsb游戏

    第一步: 最新的cocos2d-x.下载地址https://github.com/cocos2d/cocos2d-x github上最新的引擎,值得注意的是官网上发布的引擎是稳定版.选择哪种就看个人喜 ...

  8. cocos2d(3.0)一些基础的东西

    1.创建项目后环境配置: 附加文件夹:加入 $(EngineRoot) $(EngineRoot)cocos $(EngineRoot)cocos\editor-support $(EngineRoo ...

  9. 如何在Cocos2D 1.0 中掩饰一个精灵(五)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 掩饰和CCRenderTexture CCRenderTextu ...

随机推荐

  1. android透明度和css透明度

    值越小,越透明 css:0.1-------1 android:#00-----------#ff

  2. Callable,Runnable比较及用法

    http://blog.csdn.net/xtwolf008/article/details/7713580 http://www.cnblogs.com/whgw/archive/2011/09/2 ...

  3. adobe reader安装完成之前被中断,错误代码150210解决方法

    adobe reader安装完成之前被中断,错误代码150210解决方法出现这种情况是因为之前安装过adobe reader但是没有卸载删除干净进而导致重新安装时无法安装.为什么卸载不了大多数是因为3 ...

  4. firefox必备扩展

    1.首先,当然要推荐 Adblock Plus 安装地址:https://adblockplus.org/zh_CN/firefox 作用:屏蔽广告,从此和该死的广告说拜拜吧(不论是百度推广,还是别的 ...

  5. Mac 安装Qt5.1编译出现的错误解决

    错误提示: :-1: 错误:Xcode is not installed in /Volumes/Xcode/Xcode.app/Contents/Developer. Please use xcod ...

  6. Google C++ style guide——头文件

    1.#define保护 使用#define防止头文件被多重包括.命名格式为:<PROJECT>_<PATH>_<FILE>_H_ 比如,foo中的头文件foo/sr ...

  7. 【LeetCode】【Python】Linked List Cycle

    Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...

  8. An error has occurred,See error log for more details

    解决Eclipse3.2配合MyEclipse5.0M2使用时打开JSP发生“An error has occurred,See error log for more details”错误的解决方法 ...

  9. php汉字转Unicode编码函数

    /** * $str 原始字符串 * $encoding 原始字符串的编码,默认GBK * $prefix 编码后的前缀,默认"&#" * $postfix 编码后的后缀, ...

  10. smarty模版使用php标签,获取模版变量!

    <ul>{/foreach from=$A key=k item=val/}{/php/} $val = $this->_tpl_vars[val]; $date = substr( ...