【发布时间】:2014-05-14 23:10:04
【问题描述】:
我正在检测两个精灵之间的碰撞,并且在碰撞时我试图在场景中添加更多精灵。检测到碰撞时调用以下方法。
-(void) contactBetweenGreenBallAndRedBall:(SKPhysicsContact *) contact
{
if([self isLevelCompleted])
{
[self addRedBallsToScene:10];
}
}
// add red balls to the scene
-(void) addRedBallsToScene:(int) numberOfRedBalls
{
for(int i = 1; i <= numberOfRedBalls; i++)
{
int x = arc4random() % (int) self.size.width;
int y = arc4random() % (int) self.size.height;
RedBall *redBall = [[RedBall alloc] init];
redBall.name = @"redball";
redBall.position = CGPointMake(x, y);
[self addChild:redBall];
[_redBalls addObject:redBall];
[redBall.physicsBody applyImpulse:CGVectorMake(5.0, -10.0f)];
}
}
即使我将 redBall 添加到场景中,我也从未见过它。场景从不显示新添加的红球。
更新:我注意到精灵正在被添加,但由于某种原因,它们被添加到 0,0 为什么会这样?
【问题讨论】:
-
在此代码 sn-p 中,如果 self.size 为 0,0,则它只能为 0,0。设置断点并检查。
标签: ios sprite-kit