gpt4 book ai didi

swift - 尝试调整 sknode 的大小会产生错误 "Cannot assign to the result of this expression"?

转载 作者:搜寻专家 更新时间:2023-10-31 22:23:44 25 4
gpt4 key购买 nike

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

最佳答案

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

关于swift - 尝试调整 sknode 的大小会产生错误 "Cannot assign to the result of this expression"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25539611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com