【发布时间】:2014-12-24 10:39:13
【问题描述】:
在我的代码中,我有一个开始下落的球,每次你点击它时它都会应用下面的代码。这在 iPhone 上完美运行,但我也在为 iPad 开发。现在在 iPad 上,球显然必须更大,我也希望将相同的效果应用于这些球。我试着做数学来得到球大小的相对力,我知道我做的数学是正确的,但必须有一个更简单的方法来完成这个。任何帮助将不胜感激!
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
// if ball is tapped apply impulse
if ([node.name isEqualToString:@"ball"]) {
node.physicsBody.velocity = CGVectorMake(0, 15);
[node.physicsBody applyImpulse:
CGVectorMake(0, 50)];
[GameState sharedInstance].easyScore += 1;
[_lblEasyScore setText:[NSString stringWithFormat:@"%d", [GameState sharedInstance].easyScore]];
NSLog(@"ball pressed");
}
}
【问题讨论】:
标签: objective-c iphone vector sprite-kit