Cocos2d游戏开发 2-Hello World

1. The UIKit coordinate system has the origin (0,0) at the upper left of the screen. How- ever, Cocos2D uses the OpenGL ES coordinate system, which places the origin (0,0) at the lower left of the screen.


if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
			vikingSprite.scaleX = screenSize.width/1024.0f;
			vikingSprite.scaleY = screenSize.height/768.0f;	
		}

2. 根据屏幕的大小,对vikingSprite进行缩放


3.  In Cocos2D the z value determines the order in which your CCNodes (sprites, layers, etc.) will be drawn.



        [self scheduleUpdate];                   


5. call to the Cocos2D scheduler to call the update method every time this layer is set to be rendered on the screen. That means the update method was called before every frame of Space Viking is to be rendered. 

-(void) update:(ccTime)deltaTime
{
    [self applyJoystick:leftJoystick toNode:vikingSprite forTimeDelta:deltaTime];
}


6. The Cocos2D Director runs the Space Viking game loop at 60 frames per second, so the update method is called approximately 60 times a second. deltaTime means how much time (deltaTime) has elapsed between the last update call and now.


7. tag

#define kVikingSprite 10
[self addChild:tempSprite z:0 tag:kVikingSprite];
CCSprite *tempSprite = [self getChildByTag:kVikingSprite];

Terminology Review

1. Image Files
Your characters start out as images on the flash storage of the iPhone/iPad. Once the images are loaded into memory, they are stored in an uncompressed texture format. PNG is the preferred format for images on the iOS devices.


2. Texture

The image file of your character has to be decompressed and possibly converted into a format that the iPhone and iPad GPU can understand and loaded into RAM before it can be used. The loaded image in RAM is referred to as a texture.This is what OpenGL ES draws on the screen.


3. Texture Atlas or Sprite Sheet

In order to save on memory and reduce the amount of wasted empty space in your textures, you want to combine them into one larger texture, called a texture atlas. The texture atlas is simply a large texture, containing your images, from which smaller textures for each of your images can be cut or extracted from. One of the keys to get- ting more graphical performance is handing OpenGL ES as few textures as you can in one pass by having a lot of textures combined into the texture atlas. The key is in batching the draw calls and reducing the number of textures OpenGL ES binds to, both accomplished by using a texture atlas in Cocos2D via theCCSpriteBatchNode.

Texture Atlas

1. For each sprite, OpenGL ES has to bind to the texture for that CCSprite and then draw (also called rendering) the sprite onscreen.


2. Your game will run faster if you do all of your rendering work with the least number of OpenGL ES calls.


3. The CCSpriteBatchNode is a special class in Cocos2D that can act as the parent to a host of CCSprites. It sits between the CCLayer and the CCSprites. All of the draw calls for the CCSprites are batched and done byCCSpriteBatchNode at once. 


4. The large performance savings is not from just batching the calls together but from combining all of the little textures into one large texture that OpenGL ES has to bind just once.


5. Top Reasons to Use a Texture Atlas/Sprite Sheet
    (1)Reduced OpenGL ES bind calls—the more images contained in the texture atlas, the greater the reduction.
    (2)Reduced memory footprint for the images stored as textures in memory.
    (3)Easy method to trim and save on transparent space in your images, allowing for more images/texture in the               same space.
    (4) Zwoptex and TexturePacker are fully supported by Cocos2D, so creating and using texture atlases is painless.


6. CCSpriteBatchNode 

CCSpriteBatchNode *chapter2SpriteBatchNode;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"scene1atlas.plist"];
chapter2SpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"scene1atlas.png"];
} else {
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"scene1atlasiPhone.plist"];
chapter2SpriteBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"scene1atlasiPhone.png"];
}
		
vikingSprite = [CCSprite spriteWithSpriteFrameName:@"sv_anim_1.png"];
vikingSprite.position = ccp(screenSize.width/2, screenSize.height*0.17f);
		
[chapter2SpriteBatchNode addChild:vikingSprite];
[self addChild:chapter2SpriteBatchNode];
		
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
			vikingSprite.scaleX = screenSize.width/1024.0f;
			vikingSprite.scaleY = screenSize.height/768.0f;	
}


7. The Sprite frames are the dimensions and location of all of the images inside of the texture atlas. This plist is what allows Cocos2D to extract the images from the texture atlas PNG and render them onscreen. Creates the vikingSprite with only the name of the frame that Cocos2D should use to extract the image from the texture atlas.

8. The steps required to use a texture atlas in Cocos2D are loading the sprite frames into the cache and creating a CCSpriteBatchNode with the texture atlas image.


9. CCSprite and CCSpriteFrame 的区别

CCSprite 是在界面上可以移动的图片,可以用spriteWithFile:创建,或者spriteWithSpriteFrameName:通过指定Frame的名称,从texture atlas中提取。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值