【发布时间】:2012-11-01 15:19:02
【问题描述】:
我的目标是在用户触摸屏幕后向屏幕添加精灵 leftOn。
这是我的代码:
-(void)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector]convertToGL:location];
if (CGRectContainsPoint([leftOff boundingBox],location)) {
CCLOG(@"Left Pressed");
[self addChild:leftOn];
}
}
日志总是输出“Left Pressed”,但在没有添加精灵的情况下停止运行。 如果我在它确实显示的 init 方法中添加精灵。另外,我尝试更改精灵的顺序,例如 [self addChild:leftOn z:2],但它仍然不显示。
【问题讨论】:
-
leftOn 存在吗?显示你在哪里分配 leftOn
标签: cocos2d-iphone touch sprite addchild