gpt4 book ai didi

swift - 在另一个中添加 SKShapeNode

转载 作者:行者123 更新时间:2023-11-30 10:14:41 25 4
gpt4 key购买 nike

我想在另一个正方形里画一个正方形;但我无法以正确的方式定位第二个。根据第一个平方坐标进行定位可以做什么?

    var tileBackground = SKShapeNode(rectOfSize: CGSize(width: screenWidth, height: screenWidth))
tileBackground.name = "tileBackground"
tileBackground.fillColor = SKColor.whiteColor()
tileBackground.position = CGPoint(x: frame.midX, y: frame.midY);
self.addChild(tileBackground)

var tile = SKShapeNode(rectOfSize: CGSize(width: tileSize, height: tileSize))
tile.name = "tile1"
tile.fillColor = SKColor.redColor()
tile.position = CGPointMake(100,100)
tileBackground.addChild(tile)

最佳答案

您应该使用 SKSpriteNode 代替。这样您就可以轻松添加它,而无需手动设置位置。因为在 SKSpriteNode 中,中心始终是节点的中心:

var tileBackground = SKSpriteNode(color: UIColor.whiteColor(), size: CGSizeMake(width: screenWidth, height: screenWidth))
tileBackground.name = "tileBackground"
tileBackground.position = CGPoint(x: frame.midX, y: frame.midY);
self.addChild(tileBackground)


var tile = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: tileSize, height: tileSize))
tile.name = "tile1"
tileBackground.addChild(tile)

关于swift - 在另一个中添加 SKShapeNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30845539/

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