gpt4 book ai didi

iphone - 如何让 Sprite 在点击时随着各种动画消失?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:04 27 4
gpt4 key购买 nike

我是 Cocos2D 的新手。我正在为 iPhone 制作一个简单的游戏,我希望我的 Sprite 随着一些动画消失。到目前为止,我可以使用以下代码让它消失:-

-(void)selectSpriteForTouch:(CGPoint)touchLocation
{

for (CCSprite *sprite in targets)
{

if (CGRectContainsPoint(sprite.boundingBox, touchLocation))
{
NSLog(@"sprite was touched");

[sprite.parent removeChild:sprite cleanup:YES];
[[SimpleAudioEngine sharedEngine] playEffect:@"pop.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];

}
}
}

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

for( UITouch *touch in touches )
{

CGPoint location = [touch locationInView: [touch view]];

location = [[CCDirector sharedDirector] convertToGL: location];

[self selectSpriteForTouch:location];
NSLog(@"touch was detected");
}
}

现在我想让 Sprite 消失并带有一些动画或任何效果。我该怎么做?

最佳答案

例如,这会使您的 Sprite 缩小直到消失,然后将其从其父级中移除:

-(void)selectSpriteForTouch:(CGPoint)touchLocation
...
if (CGRectContainsPoint(sprite.boundingBox, touchLocation))
{
[sprite runAction:[CCSequence actions:
[CCScaleTo actionWithDuration:0.4 scale:0],
[CCCallFuncO actionWithTarget:self selector:@selector(removeSprite:) object:sprite],
nil]];
...//play audio etc
}
....
}

-(void) removeSprite:(CCSprite*) s
{
[s.parent removeChild:s cleanup:YES];
}

对于其他操作,请尝试 CCMoveToCCJumpToCCRotateBy。您可以一次运行多个操作,因此在我提供的 runAction: 行上方,尝试另一个 [sprite runAction:[CCRotateBy actionWithDuration:0.4 angle:360]]

关于iphone - 如何让 Sprite 在点击时随着各种动画消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7736922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com