Create spritesheet
@H_301_4@ 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 thisBIGimage in the game. @H_301_4@ Until… I started to look in the game development,I only know that this is actually created byspritesheetprogram/app. @H_301_4@ Here I will be usingTexturePacker. @H_301_4@ 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
@H_301_4@ First of all,I’m going to do this in Cocos2d-x engine,so selectCocos2dhere. @H_301_4@ Now,drag images to theBox @H_301_4@ Here I drag 3 bird images,and you can see the left pane,there arehero_01.png
,hero_02.png
,244)">hero_03.png,these are the original file name.
@H_301_4@ Once you’ve done,selectPublish sprite sheet
@H_301_4@ It will prompt you twice,one is to save the plist file contains the Meta data of the original images such asframe
,244)">offset,244)">rotated,etc. It may sound complicated,but no worry,Cocos2d-x will handle it.
@H_301_4@ The second prompt is to save the merged image.
@H_301_4@ And you’ve done.
Use in Cocos2d-x
@H_301_4@ File structure @H_301_4@ InAppDelegate.cppapplicationDidFinishLaunching()
method,add
- I’m a iPhone user,thus I fix the resolution to320 x 480for simplicity
- In this case,I put the sprite sheet underimagesdirectory,thus I add the search path
images
toFileUtils
- Add sprite sheet to cache
Create a sprite object (bird in this case)
@H_301_4@ I just name itHero
. EditHero.h
@H_301_4@ andHero.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 onhero.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
@H_301_4@ EditGameScene.cpp,under theinit()
method,add the code below right beforereturn
statement
@H_301_4@ This is to instantiate aHeroobject,set the position to center of screen then add to current scene.
@H_301_4@ Run it and you will get the animated bird,see screenshot below.
@H_301_4@ Done.