在 Xcode 中创建操纵杆/方向键来移动 UIImageView(包含角色)
我有一个 UIImageView 连接到我编码的游戏。但是我想知道如何通过操纵杆/方向键移动这个 UIImageView。我还没有编写 JoyStick 或 D-Pad 代码,因为我不知道如何编写。如果您能告诉我如何去做这件事,我将非常感激。
编辑:
虚拟操纵杆(在应用程序中)。
I have a UIImageView connected to a game I coded. However I would like to know how I could move this UIImageView via a Joystick/D-Pad. I have not coded a JoyStick or a D-Pad as I don't know how to. I would really appreciate it if you could tell me how I could go abouts doing this.
Edit:
A virtual joystick (in the app).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是越狱的 iPhone,您可以尝试本教程来使用rs232 用于与 iphone/ipod 进行串行通信。
否则,如果您想合法地做事,连接到 iPhone 的 30 针串行连接或通过蓝牙的外部操纵杆要求您是 注册 iOS 开发者(RAD),也是 Made for iPod 的一部分计划(MFI)。
在 iOS 上设置与配件的通信需要使用 ExternalAccessoryFramework,其中有一个 Apple 示例项目:EADemo,以及此处的 Apple 演练 外部配件编程主题。
还有一本名为 Building iPhone OS Accessories 的 Apress 书,以及一个相关的乒乓球游戏演示项目这与你想做的类似。本书将引导您了解如何设置 EAAccessoryFramwork 代码,以及如何构建游戏控制器硬件,但没有描述如何为配件编写任何固件,因为您需要获得 MFi 许可证才能获取此信息。
我希望这足以让您开始。 :)
If you are working with a jailbroken iphone, you can try out this tutorial for using rs232 for serial communication with the iphone/ipod.
Otherwise if you want to do things legitimately, an exernal joystick connected to the iphone's 30 pin seral connection, or through bluetooth requires that you are a Registered iOS Developer(RAD), and also part of the Made for iPod Program(MFI).
Setting up communication with an accessory on iOS requires the use of the ExternalAccessoryFramework, of which there is an Apple example project here: EADemo, and an Apple walkthrough here External Accessory Programming Topics.
There is also an Apress book called Building iPhone OS Accessories, and a related demo project of a pong game which is similar to what you want to do. The book walks you through how to set up the EAAccessoryFramwork code, as well as how to build the game controller hardware, but does not describe how to write any firmware for the accessory, as you need to be an MFi licence to attain this information.
I hope that is enough to get you started. :)
如果您希望创建虚拟方向键,请尝试以下操作:
创建 4 个 UIButton 对象,并使用方向箭头图形设置它们(我建议在 IB 中执行此部分)。
然后创建 4 个独立的 IBAction 方法,并通过 IB 或以编程方式在
viewDidLoad
中将它们链接到您的按钮。每个 IBAction 方法应如下所示:
您可以将 10 更改为您希望图像移动的任意像素数。
如果您希望在移动视图时进行动画处理,您可以将移动代码包装在动画块中:
如果您需要任何进一步的说明,请告诉我。
If your looking to create a virtual dpad try the following:
Create 4 UIButton objects, and set them up with direction arrow graphics (I would recommend doing this part in IB).
Then Create 4 seperate IBAction methods and link them to your buttons through IB or programmatically in
viewDidLoad
.Each IBAction method should look something like this:
You can change 10 to any number of pixels you want your image to move.
If you want the view to be animated when you move it you can wrap your movement code insdide an animation block:
Let me know if you need any further clarification.