3

I have created a subclass of SKNode called level and I'm trying to change it's size, however I get the error "Cannot assign to the result of this expression".

What am I doing wrong?

class Level: SKNode {

    override init() {
        super.init()
        self.frame.size= CGSizeMake(width: 100, height: 100) // Cannot assign to the result of this expression
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
lisovaccaro
  • 32,502
  • 98
  • 258
  • 410

1 Answers1

4

The frame property is readonly, as you can see in SKNode.h

@property (SK_NONATOMIC_IOSONLY, readonly) CGRect frame;

I suggest you to read a bit more of the SKNode documentation: https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/Reference/Reference.html

In the document you will find this paragraph:

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.

So frame is computed by SKNode subclasses based on different properties

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
  • the self.frame property is in fact read only, which satisfies your question, therefore shouldn't this answer be marked as such? – Shawn J. Molloy May 30 '15 at 19:43