【发布时间】:2014-09-08 16:33:18
【问题描述】:
我曾多次尝试为我的新迷宫游戏实现方向键,但在这样做时遇到了麻烦。我以 4 个 UIButtons 的样式进行操作,如果您按下一个,它会向上、向下、向左或向右移动另一个图像。我试过使用quartzcore和CAAnimation,但只知道有限的代码。
我已经声明了方法和按钮,但无法编写有效的代码。
我在做:
-(IBAction)Up:(id)sender{
CGPoint origin1 = self.Player.center;
CGPoint target1 = CGPointMake(self.Player.center.x, self.Player.center.y-124);
CABasicAnimation *bounce1 = [CABasicAnimation animationWithKeyPath:@"position.y"];
bounce1.duration = 0.1;
bounce1.fromValue = [NSNumber numberWithInt:origin1.y];
bounce1.toValue = [NSNumber numberWithInt:target1.y];
[self.Player.layer addAnimation:bounce1 forKey:@"position"];
}
幽灵向下移动,但立即弹回。我已经被难住了好几个小时了,这可能让我很生气,但请理解我的笨拙。
【问题讨论】: