【发布时间】:2014-08-13 00:16:56
【问题描述】:
当用户触摸屏幕上的某个点时,我试图让精灵节点移动。正在识别我的触摸,但没有发生任何动作!
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
self.anchorPoint = CGPointMake(0.5, 0.5);
SKSpriteNode *_box = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(50, 50)];
_box.position = CGPointMake(0.5,0.5);
[_box addChild:_box];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
_currentTouch = touch;
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
CGPoint currentLocation = [_currentTouch locationInView:_currentTouch.view];
if (currentLocation.y > 300) {
_box.position = CGPointMake(_box.position.x, _box.position.y + 20);
NSLog(@"touching");
}
}
@end
我不确定我是不是走错了路,但我可以拼命寻求帮助!谢谢!
【问题讨论】:
标签: ios xcode position sprite-kit touchesbegan