Swift 3中的CGRectGetMidX/Y在哪里 [英] Where is CGRectGetMidX/Y in Swift 3

查看:1167
本文介绍了Swift 3中的CGRectGetMidX/Y在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Siwft 3中,找不到用于计算节点位置的CGRectGetMidX和Y.我也找不到CGPointMake.在这种情况下,如何在SKScene的中心设置节点?

IN Siwft 3, I could not find CGRectGetMidX and Y which I used to calclate position of nodes. Also I could not find CGPointMake. IN this case, how am I able to set nodes in the center of SKScene?

谢谢!

更新: 通过这样编写,我创建了一个节点并指定了它的位置;

Update: I created a node and specified the position of it, by writing this way;

let node = SKSpriteNode()
node.position = CGPoint(x:self.frame.size.width/2, y:self.frame.size.height/2)
node.size = CGSize(width: 100, height: 100)
node.color = SKColor.red
self.addChild(node)

为什么它在其他地方,例如与指定位置不同的地方?首先,我认为Swift3发生了变化,而CGPointMake的过时导致了此问题,但似乎并非是原因.在这种情况下,使用CGRect更好吗?如果您可以编写解决此职位问题的代码,这将非常有帮助.再次感谢您的帮助.

Why is it somewhere else like different place from the specified location? I firstly thought there was a change in Swift3 and the depresciation of CGPointMake caused this problem, but it does not seem like it is the cause. In this case, is the use of CGRect better? It is very helpful if you could write code that fixs this position issue. Again, thank you for your help.

推荐答案

在Swift中,您不应使用那些旧样式符号.只需使用构造函数和属性即可:

In Swift you shouldn't use those old style notations. Just use the constructors and properties:

let point = CGPoint(x: 1, y: 2)
let rect = CGRect(x: 1, y: 2, width: 3, height: 4)
let mx = rect.midX

这篇关于Swift 3中的CGRectGetMidX/Y在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆