我创建了一个名为level的SKNode子类,我正在尝试更改它的大小,但是我收到错误“无法分配给这个表达式的结果”。
我做错了什么?
class Level: SKNode {
override init() {
super.init()
self.frame.size= CGSizeMake(width: 100, height: 100) // Cannot assign to the result of this expression
答案 0 :(得分:4)
frame
属性是只读的,如您在SKNode.h中所见
@property (SK_NONATOMIC_IOSONLY, readonly) CGRect frame;
我建议您阅读更多SKNode
文档:https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/Reference/Reference.html
在文档中,您将找到以下段落:
The frame property provides the bounding rectangle for a node’s visual content, modified
by the scale and rotation properties. The frame is non-empty if the node’s class draws
content. Each node subclass determines the size of this content differently. In some
subclasses, the size of the node’s content is declared explicitly, such as in the
SKSpriteNode class. In other subclasses, the content size is calculated implicitly by the
class using other object properties. For example, a SKLabelNode object determines its
content size using the label’s message text and font characteristics.
所以frame
由SKNode子类根据不同的属性计算