【发布时间】:2011-04-20 17:11:59
【问题描述】:
我在现场有两个 CCSprite
CCSprite *spriteA; CCSprite *spriteB;
spriteB的位置是固定的,而spriteA的位置是不固定的。我碰到了spriteA,它只能沿直线移动,只有“上/下/左/右”四个方向,不能斜线,还有它可以移动,直到 spriteB 停止它。比如我(spriteA)可以一直跑,直到我前面的墙(spriteB)阻止我。
我使用以下代码
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return YES;}
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [touch locationInView: [touch view]];
CGPoint convertedLocation = [[CCDirector sharedDirector] convertToGL:location];
[spriteA stopAllActions];
[spriteA runAction: [CCMoveTo actionWithDuration:1 position:convertedLocation]];
}
它可以移动,但不只是四个方向,如果 spriteB 在 spriteA 的前面,我如何使用 spriteB 停止 spriteA? 谢谢
【问题讨论】:
标签: iphone cocos2d-iphone