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

SKNode.hframeでわかるように、プロパティは読み取り専用です。

@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 に答える