gpt4 book ai didi

ios - 快速分组多个 Sprite

转载 作者:可可西里 更新时间:2023-11-01 02:17:58 26 4
gpt4 key购买 nike

我正在尝试将 4 个 Sprite 添加到一个 View 中,每个 Sprite 都在一个假想正方形的另一个角落,而不是围绕中心旋转所有 Sprite 。完成此任务的最佳方法是什么?

我知道如何旋转每个 Sprite ,但也许有一种方法可以将多个 Sprite 分组,比如将它们放在一个容器中?

How the result should look like

最佳答案

这是我的工作代码。

import SpriteKit

let player = SKNode()
let playerTopLeft = SKSpriteNode(color: UIColor.yellowColor(), size: CGSizeMake(20, 20))
let playerTopRight = SKSpriteNode(color: UIColor.yellowColor(), size: CGSizeMake(20, 20))
let playerBottomRight = SKSpriteNode(color: UIColor.yellowColor(), size: CGSizeMake(20, 20))
let playerBottomLeft = SKSpriteNode(color: UIColor.yellowColor(), size: CGSizeMake(20, 20))

class GameScene: SKScene {

override func didMoveToView(view: SKView) {
backgroundColor = SKColor.blackColor()

player.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
addChild(player)

playerTopLeft.position = CGPoint(x:-40, y:-40)
player.addChild(playerTopLeft)

playerTopRight.position = CGPoint(x:40, y:-40)
player.addChild(playerTopRight)

playerBottomRight.position = CGPoint(x:40, y:40)
player.addChild(playerBottomRight)

playerBottomLeft.position = CGPoint(x:-40, y:40)
player.addChild(playerBottomLeft)

}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

for touch in touches {

let rotate = SKAction.rotateByAngle(CGFloat(-M_PI_2), duration:1)
player.runAction(rotate)

}
}
}

关于ios - 快速分组多个 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35119028/

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