有人可以帮助我。我正在尝试使用 CCSprite 作为移动控制器,我可以拖动(左/右)来移动我的玩家角色。问题是当我在 CCSprite 之外触摸时,它仍然检测为 Active,这是我在 ccTouchBegan 上设置为 ACTIVE 的枚举,在 ccTouchEnded 方法中设置为 IDLE。默认情况下它处于空闲状态。不知道为什么当我开始触摸我的 CCSprite 之外时它会激活。
请指教。
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
BOOL touched = NO;
CGPoint loc = [touch locationInView: touch.view];
loc = [[CCDirector sharedDirector] convertToGL: loc];
//avatar is a CCSprite...
//inside of IF statement should not execute if I touch anywhere on screen
//outside of self.avatar sprite, but it still executes....
if ( CGRectContainsPoint( [self.avatar boundingBox], loc) );
{
self.state = ACTIVE;
self.action = MOVE_STOPPED; //player decides which direction to move, based on action state
self.currPoint = self.prevPoint = self.avatar.position;
touched = YES;
}
return touched;
}