Cocos2d-x 使用 TexturePacker制作一个英雄,老外写的
来源:互联网 发布:淘宝男模特红人 编辑:程序博客网 时间:2024/05/06 06:44
Create spritesheet
Have you seen this sort of image before? The first time I saw this I thought this is created using Photoshop, and I also have no idea how to use this BIG image in the game.
Until… I started to look in the game development, I only know that this is actually created by spritesheet program/app.
Here I will be using TexturePacker.
Why? I have seen many game tutorials are talking about this, I tried it and found that it is very easy to use.
How to use demo
First of all, I’m going to do this in Cocos2d-x engine, so select Cocos2d here.
Now, drag images to the box
Here I drag 3 bird images, and you can see the left pane, there are hero_01.png
, hero_02.png
, hero_03.png
, these are the original file name.
Once you’ve done, select Publish sprite sheet
It will prompt you twice, one is to save the plist file contains the meta data of the original images such as frame
,offset
, rotated
, etc. It may sound complicated, but no worry, Cocos2d-x will handle it.
The second prompt is to save the merged image.
And you’ve done.
Use in Cocos2d-x
File structure
In AppDelegate.cpp applicationDidFinishLaunching()
method, add
- I’m a iPhone user, thus I fix the resolution to 320 x 480 for simplicity
- In this case, I put the sprite sheet under images directory, thus I add the search path
images
toFileUtils
- Add sprite sheet to cache
Create a sprite object (bird in this case)
I just name it Hero
. Edit Hero.h
and Hero.cpp
- Load an image for the Hero (a.k.a bird) by default during object instantiation
- Make the bird fly by running the move action
- As we know that there are 3 images on hero.plist, thus fix it to 3. Then add all these 3 images (get from sprite frame cache) to an array, and then repeat it forever.
Add hero to GameScene
Edit GameScene.cpp, under the init()
method, add the code below right before return
statement
This is to instantiate a Hero object, set the position to center of screen then add to current scene.
Run it and you will get the animated bird, see screenshot below.
Done.
- Cocos2d-x 使用 TexturePacker制作一个英雄,老外写的
- Cocos2d-x TexturePacker的使用
- Cocos2d-x TexturePacker的使用
- Cocos2d-x:TexturePacker的使用
- cocos2d-x之texturepacker的使用
- 【cocos2d-x】TexturePacker 使用心得
- 【Cocos2d-x游戏引擎开发笔记(22)】TexturePacker的使用
- 【Cocos2d-x游戏引擎开发笔记(22)】TexturePacker的使用
- 【cocos2d-x 3】关于plist和TexturePacker的简单使用
- cocos2d 使用TexturePacker制作plist文件
- cocos2d-x 项目里使用TexturePacker
- Cocos2d-x:制作一个动态的精灵
- cocos2d-x使用TexturePacker打包图片及使用生成的plist文件创建精灵动画
- cocos2d-x使用TexturePacker打包图片及使用生成的plist文件创建精灵动画
- TexturePacker打包后的带透明度的图片在cocos2d-x中使用时有黑边
- TexturePacker打包后的文件在cocos2d-x加载和使用
- cocos2d-x使用texturepacker打包swf动画及代码调用
- Cocos2d-x—使用TexturePacker对图片进行打包、加密
- Active Server Pages 错误 ‘ASP 0201′
- arm-linux-gdb和gdbserver调试交叉编译的程序
- android 4.0特性
- form_tag (ActionView::Helpers::FormTagHelper)
- LeetCode 148 Sort List
- Cocos2d-x 使用 TexturePacker制作一个英雄,老外写的
- Hive 中 Array、Map、Struct 的使用
- 插入排序
- WWDC 2014 Session笔记 - iOS界面开发的大一统
- 最新新娘编发,不可错过
- iOS开发之让你的应用“动”起来(动画)
- 快速搞懂 SQL Server 的锁定和阻塞
- Android二维码
- 黑马程序员-String类