3

我创建了一个名为 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
4

1 回答 1

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 子类根据不同的属性计算的

于 2014-08-28T04:46:37.357 回答