如何将值转换为 CGPoint?
我的 Xcode 项目有问题,希望你能帮助我! 我刚刚开始编码,所以我的问题应该很容易解决。
我想用两个球拍和一个球制作一个乒乓球游戏。我有一个介于 0 和 1 之间的值。如果该值很高,桨也应该上升。可以使用“CGPoint”更改桨位置,但如何将我的值转换为点?
请帮我。 来自德国的感谢和问候:)
I´ve got a problem with my Xcode-Project and hope you can help me!
I just began coding, so my problem should be very easy to solve.
I wanna make a Pong Game with two paddles and a ball. I have got a value, which is between 0 and 1. If the value is high the paddle should also go up. The paddle position can be changed with "CGPoint", but how can I convert my value to a point?
Please help me.
Thanks and greets from Germany :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CGPoint
是一个二维点。您可以使用 CGPointMake(x,y) 创建一个 CGPoint。
当您的值介于 0 和 1 之间时,您可能需要通过乘以常数因子来缩放 x 或 y。
CGPoint
is a 2-dimensional point.You can create a
CGPoint
withCGPointMake(x,y)
.When your value is between 0 and 1 you may want to scale either x or y by multiplying with a constant factor.
我对桨控制有一个更好的想法:
您可以使用用户触摸输入来控制桨:
当用户触摸屏幕时,桨移动到触摸的 .y 位置,但保持在默认的 x 坐标上!
这样,控制就会更加流畅。试试吧!
Viel Spass beim 程序 :D
I have a better idea for the paddle controll:
You can use the users touch imput to controll the paddle:
When the user touches the screen, the paddle moves to the .y position of the touch but stays on its defaulf x cordinates!
That way, the controlls would be more fluid. Just try it out!
Viel Spass beim programmieren :D
这是我的应用程序中完成这项工作的确切代码
This is exact code from my app to do this job