开发者

Showing a frame when collision is detected (cocos2d iPhone)

I have a hero character all set up with a CCSpriteBatchNode, which has all the animation and frames. But I wonder, how do I display a frame when the hero is hit (I set up collision detection already). How do I make this happen? Do I put it inside t开发者_Python百科he CCSpriteBatchNode? It's not part of moving, only for special occasions.


You can set your hero invisible ( [sprite setVisible: NO]) and show another sprite at the hero's position.

More then it, you can keep this sprite in your hero class object and provide a method which will change the visible sprite when collision happens. Something like this

-(void) onCollision
{
    [heroMainSprite setVisible:NO];
    [heroCollisionSprite setVisible:YES];
}

Such solution will also preserve all your logic, that has been done before.


When hero gets hit.. Change the texture..

[spr setTextureRect:CGRectMake(startX, startY, width, height)];

It needs to be in the same batch node as the rest of the animation..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜