cocos2dx day 2 - Sprites
1.Sprite
对sprite设置anchor point,对应的位置
- // DEFAULT anchor point for all Sprites
- mySprite->setAnchorPoint(0.5, 0.5);
- // bottom left
- mySprite->setAnchorPoint(, );
- // top left
- mySprite->setAnchorPoint(, );
- // bottom right
- mySprite->setAnchorPoint(, );
- // top right
- mySprite->setAnchorPoint(, );
2.Actions - By and To, what is the difference?
A By
is relative to the current state of the Node
. A To
action is absolute, meaning it doesn't take into account the current state of the Node
- auto mySprite = Sprite::create("mysprite.png");
- mySprite->setPosition(Vec2(, ));
- // MoveBy - lets move the sprite by 500 on the x axis over 2 seconds
- // MoveBy is relative - since x = 200 + 200 move = x is now 400 after the move
- auto moveBy = MoveBy::create(, Vec2(, mySprite->getPositionY()));
- // MoveTo - lets move the new sprite to 300 x 256 over 2 seconds
- // MoveTo is absolute - The sprite gets moved to 300 x 256 regardless of
- // where it is located now.
- auto moveTo = MoveTo::create(, Vec2(, mySprite->getPositionY()));
- auto seq = Sequence::create(moveBy, delay, moveTo, nullptr);
- mySprite->runAction(seq);
2.1 Move
- auto mySprite = Sprite::create("mysprite.png");
- // Move a sprite to a specific location over 2 seconds.
- auto moveTo = MoveTo::create(, Vec2(, ));
- mySprite->runAction(moveTo);
- // Move a sprite 50 pixels to the right, and 0 pixels to the top over 2 seconds.
- auto moveBy = MoveBy::create(, Vec2(, ));
- mySprite->runAction(moveBy);
2.2 Rotate
- auto mySprite = Sprite::create("mysprite.png");
- // Rotates a Node to the specific angle over 2 seconds
- auto rotateTo = RotateTo::create(2.0f, 40.0f);
- mySprite->runAction(rotateTo);
- // Rotates a Node clockwise by 40 degree over 2 seconds
- auto rotateBy = RotateBy::create(2.0f, 40.0f);
- mySprite->runAction(rotateBy);
2.3 Scale
- auto mySprite = Sprite::create("mysprite.png");
- // Scale uniformly by 3x over 2 seconds
- auto scaleBy = ScaleBy::create(2.0f, 3.0f);
- mySprite->runAction(scaleBy);
- // Scale X by 5 and Y by 3x over 2 seconds
- auto scaleBy = ScaleBy::create(2.0f, 3.0f, 3.0f);
- mySprite->runAction(scaleBy);
- // Scale to uniformly to 3x over 2 seconds
- auto scaleTo = ScaleTo::create(2.0f, 3.0f);
- mySprite->runAction(scaleTo);
- // Scale X to 5 and Y to 3x over 2 seconds
- auto scaleTo = ScaleTo::create(2.0f, 3.0f, 3.0f);
- mySprite->runAction(scaleTo);
2.4 Fade In/Out
- auto mySprite = Sprite::create("mysprite.png");
- // fades in the sprite in 1 seconds
- auto fadeIn = FadeIn::create(1.0f);
- mySprite->runAction(fadeIn);
- // fades out the sprite in 2 seconds
- auto fadeOut = FadeOut::create(2.0f);
- mySprite->runAction(fadeOut);
2.5 Tint
- auto mySprite = Sprite::create("mysprite.png");
- // Tints a node to the specified RGB values
- auto tintTo = TintTo::create(2.0f, 120.0f, 232.0f, 254.0f);
- mySprite->runAction(tintTo);
- // Tints a node BY the delta of the specified RGB values.
- auto tintBy = TintBy::create(2.0f, 120.0f, 232.0f, 254.0f);
- mySprite->runAction(tintBy);
cocos2dx day 2 - Sprites的更多相关文章
- cocos2D-X Doc
{ //https://docs.cocos2d-x.org/api-ref/index.html //https://docs.cocos.com/cocos2d-x/manual/zh/sprit ...
- cocos2d-x项目101次相遇: Scenes , Director, Layers, Sprites
cocos2d-x 101次相遇 / 文件夹 1 安装和环境搭建 -xcode 2 Scenes , Director, Layers, Sprites 3 建立图片菜单 4 在 ...
- quick cocos2dx lua 内存释放
前言 对于内存的优化,网上有很多例子和教程.总体来说,就那么几种解决方案,在最后我会简单提下,这里先说下在quick中,对于图片的处理. 1.查看内存调试信息 对于quick框架的了解,我们可以参考\ ...
- [Cocos2d-x For WP8]基础知识
一.重要概念 导演(CCDirector) 在cocos2d-x引擎中,CCDirector类是整个游戏的组织和控制核心,游戏的运行规则,游戏内的CCScene(场景).布景(CCLayer).角色( ...
- cocos2d-x 纹理深入研究 第二部分
转自:http://blog.csdn.net/qq51931373/article/details/9152227 1.纹理控制. 看此代码: CCSprite *pSprite = CCSprit ...
- 【Cocos2d入门教程二】Cocos2d-x基础篇
上一章已经学习了环境的搭建.这一章对基础概念进行掌握.内容大概有: 1.导演 2.场景 3.节点 4.层 4.精灵 1.导演(Director) 导演存在的主要作用: a.环境设定(帧率 初始化ope ...
- cocos2d-x c++和object-c内存管理比较
转自:http://www.2cto.com/kf/201307/227142.html 既然选择了C++作为游戏开发的语言, 手动的管理内存是难以避免的, 而Cocos2d-x的仿Objctive- ...
- cocos2d-x 纹理深入研究
转自:http://blog.csdn.net/qq51931373/article/details/9152227 1.纹理控制. 看此代码: CCSprite *pSprite = CCSprit ...
- 一、cocos2dx概念简介
cocos2dx概念介绍 1)scene,继承自CCScene 场景,一个游戏运行期间的显示界面,一个应用里面可以有多个场景,但是每次只能有一个是激活状态,也可以理解为一次只能显示一个界面. 例如,你 ...
随机推荐
- HTML5地理定位
1.通过navigator.geolocation来获取设备当前位置,返回一个位置对象,可以获得当前经纬度相关信息: 2.navgatior.geolocation的三个方法: getCurrentP ...
- i5 6300HQ 和 i7 6700HQ
i7 6700HQ: 四核八线程 14nm 45W 2.6-3.5GHz 支持DDR4 2133内存 三级缓存6M HD Graphics 530集显 i5 6300HQ: 四核四线程 14nm 45 ...
- MVC API 权限控制
定义一个类:TestAuthorizeAttribute public class TestAuthorizeAttribute : AuthorizeAttribute { public strin ...
- angular2-aot-webpack 生产环境下编译angular2
这里讲讲,angular2在生产模式下用webpack2进行打包的方法: //使用rollup打包还是比较坑的,功能及插件上都不如webpack, 关键不支持代码分离,导致angular里的lazy ...
- HttpClientUtil简介
使用HttpClient发送请求.接收响应. http协议可以说是现在Internet上面最重要,使用最多的协议之一了,越来越多的java应用需要使用http协议来访问网络资源,HttpClient ...
- 在as3中使用protobuf
在最近参与开发的adobe air项目中,前后端的通信协议从XML.JSON再到protobuf,最后选择protobuf原因,主要是前后端维护protobuf协议就行了,同时还可以利用IDE做一些编 ...
- 如何在JAVA中实现一个固定最大size的hashMap
如何在JAVA中实现一个固定最大size的hashMap 利用LinkedHashMap的removeEldestEntry方法,重载此方法使得这个map可以增长到最大size,之后每插入一条新的记录 ...
- JQ轮播
首先是html结构,一个简单的轮播,主要分为三大层:div>ul>li,li里面的img图片. 其次,css样式:div固定住宽高,overflow:hidden:ul的宽度建议是动态获取 ...
- WEKA运行LIBSVM出现problem evaluating classifier:rand
原来这个实验已经做了的.也出现了些问题,但是上网找到了解决方法,那个时候是完成数据挖掘的课程论文,用WEKA运行LIBSVM,也没有很深入,简单跑出结果就算了. 这次想着研讨会就讲这个,想着深入进去, ...
- 35 个 Java 代码性能优化总结
前言 代码优化,一个很重要的课题.可能有些人觉得没用,一些细小的地方有什么好修改的,改与不改对于代码的运行效率有什么影响呢?这个问题我是这么考虑的,就像大海里面的鲸鱼一样,它吃一条小虾米有用吗?没用, ...