【发布时间】:2011-08-17 20:29:09
【问题描述】:
我正在尝试开发一些简单的游戏应用。对于乒乓球风格的游戏,我有一个保持在界内的移动球和两个球拍。我实现了移动桨 1 的代码,以便它按预期反射球。
当我尝试将相同的行为添加到另一个桨时,我尝试了这个:
UITouch *touch = [[event allTouches]anyObject]; // Picks up the touch
CGPoint location = [touch locationInView:self.view]; // Gets coordinates
// to help move the paddle on the X axis; Y axis is determined by the paddle,
// so it only moves along one axis
if ([touch view] == paddle2) {
// move the second paddle
...
}
else {
// move the first paddle
...
}
但是,任何触摸都只会移动 paddle1,表明条件从未激活。根据文档,我认为通过发送[touch view] 消息,被触摸的图像视图将返回它自己的名称。
我究竟做错了什么?有更简单的方法吗?
【问题讨论】:
标签: objective-c ios4 xcode4 interface-builder