Reputation: 772
I am working on a game like tap tap ants(https://itunes.apple.com/us/app/tap-tap-ants/id348839552?mt=8) in iPhone.
I want to crop some portion of sprite. when an ant touches cake sprite, some portion of cake disappear. I researched a lot but could not find any solution.
Plz help
Upvotes: 3
Views: 1358
Reputation: 19251
In the very latest version of cocos2d-iphone, they added a class called CCClippingNode. You can use it to clip (show only part of) your node and its contents.
http://www.cocos2d-iphone.org/api-ref/2.1.0/interface_c_c_clipping_node.html
Upvotes: 0
Reputation: 2194
You can use spritesheets in the form of CCSpriteBatchNode to set a display frame on a sprite. As done so below. This allows you to select a boxed region of the spritesheet to be displayed.
CCSpriteBatchNode *caveSheet = [CCSpriteBatchNode batchNodeWithFile:@"cavey_ss3.png"];
[self addChild:caveSheet];
CCSprite *player = [CCSprite spriteWithFile:@"somethingUnimportant.png"];
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:caveSheet.texture rect:CGRectMake(0,0,300,300)];
//(x-start, y-start, width, height)
[player setDisplayFrame:frame];
Or if you want something like a notch in the corner of the image gone, then you could set up two sprites working off the same CCSpriteBatchNode, with different frames, something like in the picture below.
In this example the frames would be something like this
sprite1 has CGRectMake(0,10,10,40)
sprite 2 has CGRectMake(10,0,20,50)
but ofcourse you would have to position the sprites accordingly aswell.
Upvotes: 1