How to migrate a cocos2d v0.8.x project to v0.99

本文提供从Cocos2d v0.8.x迁移到v0.99的详细步骤,包括安装配置、代码更新及兼容性设置等。重点介绍了新版本中的CCSprite类和CCSpriteSheet类的使用方法,以及如何利用CCSpriteFrameCache来简化动画制作。

Testing your code with v0.8.2

Before using cocos2d v0.99, you should test your code with the latest version of v0.8.x.

  • Install cocos2d v0.8.2 (latest v0.8. version)
  • Compile everything
  • Update your code so that it doesn't use deprecated methods and/or interfaces

Installing v0.99

Once you have tested that your game runs without warnings using v0.8.2, you can replace cocos2d v0.8.2 with cocos2d v0.99.0.

Steps to replace it:

  • Open your game XCode project
  • From XCode remove the cocos2d folder: delete the references also moving them to the trash folder
  • download cocos2d v0.99 (latest v0.99 version)
  • copy the v0.99 cocos2d directory to your game directory
  • From XCode, include the recently copied cocos2d directory

Enabling compatibility

Once you have installed cocos2d v0.99, you should enable compatibility with v0.8.

Steps to enable compatibility:

  • edit the file cocos2d/ccConfig.h
  • uncomment the line: #define CC_COMPATIBILITY_WITH_0_8 1
// the following line should be uncommented

#define CC_COMPATIBILITY_WITH_0_8 1

If Compatiblity mode is enabled, then for each new v0.9 class, an old v0.8 class will be added as a subclass of the new one.

eg:

// if v0.8 compatiblity mode is enabled, then this code will be added

 
__attribute__( ( deprecated) )
@interface Sprite : CCSprite
@end
 
__attribute__( ( deprecated) )
@interface Director : CCDirector
@end
 
// etc... etc.. etc..

IMPORTANT : It is recommended to disable compatibility with v0.8 once your project compiles OK with v0.9.

Updating your code

Once compatibility is enabled, you can compile your project. You will find several warnings and errors, but don't panic.

Adding namespaces

v0.99 classes have the CC prefix. This prefix was added in order to prevent collision with other possible libraries or user code. So, it is safe to assume that:

  • Classes that start with CC belong to cocos2d.
  • Classes that don't start with CC don't belong to cocos2d

Example:

// v0.8.x classes

Sprite * sprite = [ Sprite sprite....] ;
Director * director = [ Director sharedDirector] ;
Scene * scene = [ Scene ...] ;
Layer * layer = [ Layer ...] ;
 
// 0.99.0 classes
CCSprite * sprite = [ CCSprite sprite....] ;
CCDirector * director = [ CCDirector sharedDirector] ;
CCScene * scene = [ CCScene ...] ;
CCLayer * layer = [ CCLayer ...] ;

There are some exceptions :

  • The CocosNode class was renamed to CCNode
  • The TextureMgr class was renamed to CCTextureCache

Updating Sprites

In v0.99 AtlasSprite and Sprite were merged in one single class: CCSprite .

New classes:

  • SpriteCCSprite
  • AtlasSpriteCCSprite
  • AtlasSpriteFrameCCSpriteFrame
  • SpriteFrameCCSpriteFrame
  • AnimationCCAnimation
  • AtlasAnimationCCAnimation
  • AtlasSpriteManagerCCSpriteSheet ← NEW NAME

Example:

// v0.8 code: Atlas Sprites

AtlasSpriteManager * mgr = [ AtlasSpriteManager spriteManager...] ;
AtlasSprite * sprite = [ mgr createSpriteWith...] ;
[ mgr addChild: sprite] ;
 
// v0.99 code
CCSpriteSheet * sheet = [ CCSpriteSheet spriteSheet...] ;
CCSprite * sprite = [ CCSprite spriteWithSpriteSheet...] ;
[ sheet addChild: sprite] ;
 
// v0.8 code: Sprites
Sprite * sprite = [ Sprite spriteWith...] ;
[ self addChild: sprite] ;
 
// v0.99 code
CCSprite * sprite = [ CCSprite spriteWith...] ;
[ self addChild: sprite] ;

As you can see, CCSprite can be used as a normal sprite or as a fast sprite when it is parented to an CCSpriteSheet .

For the moment, CCSpriteSheet has the same limitations as AtlasSpriteManager . Limitations of CCSpriteSheet :

  • Only accepts CCSprites as children
  • CCSprites must have the same texture id as the CCSpriteSheet
  • CCSprites can't contain children. Only 1 level of children is supported

Updating Animation

Migrating Animation to CCAnimation

v0.8 code:

Animation *
sapusAnim =
 [
Animation animationWithName:
@
"select"
 delay:
0.3f images:
@
"SapusSelected1.png"
, @
"SapusSelected2.png"
, @
"SapusSelected1.png"
, @
"SapusUnselected.png"
, nil
]
;

v0.99 code:

CCAnimation *
sapusAnim =
 [
CCAnimation animationWithName:
@
"select"
 delay:
0.3f]
;
[ sapusAnim addFrameWithFilename: @ "SapusSelected1.png" ] ;
[ sapusAnim addFrameWithFilename: @ "SapusSelected2.png" ] ;
[ sapusAnim addFrameWithFilename: @ "SapusSelected1.png" ] ;
[ sapusAnim addFrameWithFilename: @ "SapusUnselected.png" ] ;
Migrating AtlasAnimation to CCAnimation

v0.8 code:

AtlasAnimation *
animFly =
 [
AtlasAnimation animationWithName:
@
"fly"
 delay:
0.2f]
;
[ animFly addFrameWithRect: CGRectMake( 64 * 0 , 64 * 0 , 64 , 64 ) ] ;
[ animFly addFrameWithRect: CGRectMake( 64 * 1 , 64 * 0 , 64 , 64 ) ] ;
[ animFly addFrameWithRect: CGRectMake( 64 * 2 , 64 * 0 , 64 , 64 ) ] ;

v0.99 code:

CCAnimation *
animFly =
 [
CCAnimation animationWithName:
@
"fly"
 delay:
0.2f]
;
[ animFly addFrameWithTexture: spriteSheet.texture rect: CGRectMake( 64 * 0 , 64 * 0 , 64 , 64 ) ] ;
[ animFly addFrameWithTexture: spriteSheet.texture rect: CGRectMake( 64 * 1 , 64 * 0 , 64 , 64 ) ] ;
[ animFly addFrameWithTexture: spriteSheet.texture rect: CGRectMake( 64 * 2 , 64 * 0 , 64 , 64 ) ] ;
Taking advantage of CCSpriteFrameCache

One of the benefits of v0.99 is the CCSpriteFrameCache class, since it lets you write animation code more easily.

CCSpriteFrameCache is an sprite frame cache. Basically you can add frames to this cache, and you can get them by name. You can easily create an animation using the frame cache.

CCSpriteFrameCache supports the Zwoptex format. The zwoptex format is easy to parse and use. In case you decide not to use use, you can also add sprite frames to the cache by adding them manually, or by adding them with an NSDictionary .

eg:

// loads the sprite frames from a Zwoptex generated file

[ [ CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @ "animations/grossini.plist" ] ;
 
NSMutableArray * animFrames = [ NSMutableArray array] ;
for ( int i = 0 ; i < 14 ; i++ ) {
CCSpriteFrame * frame = [ [ CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [ NSString stringWithFormat: @ "grossini_dance_%02d.png" ,( i+ 1 ) ] ] ;
[ animFrames addObject: frame] ;
}
 
CCAnimation * animation = [ CCAnimation animationWithName: @ "dance" delay: 0.2f frames: animFrames] ;

Tips

ADD YOUR OWN EXPERIENCE HERE

Recommendations based on the experience migrating games to v0.99:

  • Automatically replace: [Director to [CCDirector
  • Automatically replace: TextureMgr to CCTextureCache
  • Automatically replace: sharedTextureMgr to sharedTextureCache
  • Be careful when replacing sprites.

Here's my blog entry about performing the transition: http://paulhart.ca/?p=12


I had to Replace

  • Sprite* s = [AtlasSprite spritWithRect:… spriteManager:mgr]

with

  • CCSprite s = [mgr createSpriteWithRect:…]

I found this useful when loading images i.e. UIIMage into a CCAnimation

CCAnimation *
an =
 [
CCAnimation animationWithName:
@
"MyOverlayAnimation"
 delay:
0.5
]
;	// :dbolli:091129 11:08:00 Init animation with no textures	// :dbolli:091205 11:15:50 Removed param 3 textures:nil for cocos2d 9.x

 
UIImage * myOverlayImage = [ UIImage imageNamed: @ "my overlay.png" ] ;
// :dbolli:091205 11:18:57 Note: This image is an example placeholder for a UIImage created on the fly within the app. addFrameWithFilename: above is the easiest way to simply load an image...
 
[ an addFrameWithTexture: [ [ CCTexture2D alloc] initWithImage: myOverlayImage] rect: CGRectMake( 0.0 , 0.0 , CGImageGetWidth( myOverlayImage.CGImage) , CGImageGetHeight( myOverlayImage.CGImage) ) ] ; // :dbolli:091205 11:18:57 Added param 2 rect:CGRectMake for cocos2d 9.x

Regards, Derek Bolli (dbolli)

### 回答1: 如果你想要在日本获得永久居留身份,你需要先申请日本的签证。有许多不同类型的签证可供选择,具体取决于你在日本的目的和活动。 其中一种常见的签证类型是工作签证,这通常需要你有一份在日本的工作合同,并且你的雇主必须向当地的劳动局申请这种签证。你也可以考虑申请留学签证,这通常需要你在日本的一所大学或学校学习。 如果你已经在日本拥有了某种签证,并且希望获得永久居留身份,你可以向日本的公民政策局申请永久居留身份。申请需要满足一些条件,包括入籍时间、工作情况、居住时间等。你可以通过查询日本政府的网站或者咨询日本领事馆了解更多信息。 ### 回答2: 要想移民日本并获得永久居民身份,以下是一些建议: 1. 具备合适的签证:首先,获得合适的签证是移民日本的第一步。常见的签证类型包括工作签证、学生签证、投资签证等。可以根据个人情况选择最适合自己的签证类型。 2. 学习日本语言和文化:日本是一个讲究礼仪和文化传统的国家。学习日本语言和了解日本文化不仅可以帮助适应当地生活,还有助于融入社会并增加与日本人交流的机会。 3. 获得就业机会:在日本找到工作并获得雇主的赞助可以增加移民的机会。具备相关技能和经验,通过良好的求职准备和积极的面试表现,增加成功找到工作的机会。 4. 掌握技术或专业知识:日本对于高技能或专业知识的人才有较高的需求。通过持续学习和培训,提升自己在特定领域的竞争力,增加被日本雇主看中的机会。 5. 遵守法律和履行义务:在日本合法居住并申请永久居民身份需要遵守当地的法律法规,并按时履行纳税义务等。保持良好的行为记录和公民意识会有助于积累社会信用和获得永久居民身份。 需要注意的是,移民日本并获得永久居民身份需要时间和努力。每个人的情况和背景不同,建议咨询专业移民律师或相关部门,以获取更详细和个性化的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值