[英]Draw a hypothetical line in swift
So in my game a have this paddle and a ball, and i want to calculate which side of the paddle that the ball hits, i found this answer in C# which shows drawing two lines like this: 因此,在我的游戏中,有一个桨和一个球,我想计算出球击中桨的哪一侧,我在C#中找到了这个答案,该图显示了绘制两条线:
So what i want to do is draw two hypothetical lines(meaning invisible to the user) so i can calculate if the ball is greater then both the lines or if its in contact with one of the sides of the paddle. 所以我想做的是画两条假想的线(对用户来说是不可见的),这样我就可以计算出球是否大于两条线,或者球是否与桨的一侧接触。
How do i draw these lines in sprite kit and swift? 如何在Sprite Kit中快速绘制这些线条?
UPDATE UPDATE
You can check the position of the ball in relation to the paddle. 您可以检查球相对于球拍的位置。
If(ballNode.position.x > paddleNode.position.x) {
// ball is on the right of the paddle
} else {
// ball is on the left of the paddle
}
If(ballNode.position.y > paddleNode.position.y) {
// ball is above the paddle
} else {
// ball is below the paddle
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.