【发布时间】:2014-03-24 04:20:08
【问题描述】:
我正在学习如何使用 SpriteKit。
问题:
作为练习,我正在尝试模拟乒乓球。我希望球的初始位置在中心,而在我的一生中,我不能将它的位置设置在中心。它总是出现在屏幕的左下角,我不知道为什么。我已将场景的缩放模式设置为等于SKSceneScaleModeAspectFill,并且我在单独的试验中尝试了以下每一行代码,以便将其位置设置为中心,但它始终保持在左下角角落。
//Attempt #1
self.ball.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)); //find the middle of each axis and put them together in one coordinate
//Attempt #2
self.ball.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2); //find the width and height of the screen, divide each by 2 and assign them to an (x,y) coordinate together
//Attempt #3
self.ball.position = CGPointMake(160, 284) //Half the width and half the height
//Attempt #4
self.ball.position = CGPointMake(320, 568) //The width and the height (I'm desperately guessing at this point)
//Attempt #5
self.ball.position = CGPointMake(0,0) //I figured I'd give it a go
这个球是SKSpriteNode 顺便说一句,我没有创建SKSpriteNode 的Ball 子类或任何东西。奇怪的是,我已经能够在屏幕上准确地在我想要的位置显示其他精灵,例如桨和得分。只是这个球不配合。我究竟做错了什么?以后如何防止出现此问题?
【问题讨论】:
-
您可能将位置设置在错误的位置。请添加一些与球节点初始化相关的代码,以及您正在执行的块。
-
“这个球是一个 SKSpriteNode,因为我没有创建一个 SKSpriteNode 的 Ball 子类或任何东西。”那么
Ball是不是 SKSpriteNode?给我们更多的代码,而不是试图描述你如何创建对象
标签: ios iphone objective-c ios7 sprite-kit