Search code examples
androidsprite-sheetcocos2d-android

How to draw only a portion of sprite sheet to CCGLSurfaceView in Android Cocos2D?


I am starting out Android Cocos2D from here. I see that a sprite image can be added directly.

However, I already got myself a huge sprite sheet, it got every single sprites used in the game.

Is there some sort of function call in Cocos2D that I can simply just specify "I want to draw a portion (x1,y1) to (x2,y2) from the sprite sheet to a location on CCGLSurfaceView"?


Solution

  • CCSpriteSheet is deprecated. It's better to use CCSpriteBatchNode instead (actually they are very similar). You can create sprites from batchNode:

    CCSprite *sprite = [CCSprite spriteWithBatchNode:batch rect:CGRectMake(x1, y1, x2, y2)];
    

    That's the objective-c code, but i thinks there is the same function in android version