[英]How do I create a file with the iOS\Cocoa Touch\Objective-C class template in Xcode
[英]multiple touch in xcode iOS objective C
我的游戏中有一个角色,可以左右移动和跳跃。 我正在使用touchesBegan来做到这一点。 但是当我向左移动(继续触摸屏幕->使角色越来越快)时,仅当我释放它时才会跳转。 我想同时跳跃和向左移动。
这是我的一些代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
if((point.x < moveLeftButton.frame.size.width))
{
if((point.y > JumpButton.frame.size.height))
{
leftSide = YES;
sanchez.image = [UIImage imageNamed:@"characterL2"];
}
}
if((point.x) > (backGround.frame.size.width - moveRightButton.frame.size.width))
{
if((point.y > JumpButton.frame.size.height))
{
rightSide = YES;
sanchez.image = [UIImage imageNamed:@"characterR2"];
}
}
if( notJumping && (point.y < JumpButton.frame.size.height) && (sanchezStopAll == NO))
{
AudioServicesPlaySystemSound(jump);
sanchezJumping = 5.5;
notJumping = NO;
}
[self animation];
}
我不使用buttonPressed,因为它们是隐藏的,我认为您无法单击隐藏的按钮。
如果未隐藏,则如下所示:
默认情况下,除非您设置multipleTouchEnabled = YES
否则您只会得到一次触摸。 然后,您的代码应该可以按预期工作。
例如:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.multipleTouchEnabled = YES;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.