ios - SpriteNode 不可见

标签 ios swift sprite-kit

我正在尝试使用以下方法创建我的用户 SpriteNode。纹理是 Kladde,图像也不为空。

func spawnPlayer() {
    if didFirstTap == true && isGameOver == false {
        let collisionMask = CollisionCategory.Surrounding.rawValue | CollisionCategory.Platform.rawValue
        let x = self.frame.size.width / 4
        let y = CGRectGetMidY(self.frame)
        let node = SKNode()
        node.position = CGPointMake(frame.size.width + playerTexture!.size().width, 0)
        playerNode = SKSpriteNode(texture: playerTexture)
        playerNode!.setScale(1.0)
        playerNode!.position = CGPointMake(x, y)
        playerNode!.speed = 1.0
        playerNode!.zRotation = 0.0
        playerNode!.physicsBody = SKPhysicsBody(circleOfRadius: playerNode!.size.height / 2)
        playerNode!.physicsBody?.dynamic = true
        playerNode!.physicsBody?.allowsRotation = false
        playerNode!.physicsBody?.categoryBitMask = CollisionCategory.Player.rawValue
        playerNode!.physicsBody?.contactTestBitMask = collisionMask
        playerNode!.physicsBody?.collisionBitMask = collisionMask
        playerNode!.physicsBody!.velocity = CGVectorMake( 0, 0 )
        node.addChild(playerNode!)
        addChild(node)
    }
}

我希望有人知道,为什么我的节点是不可见的?

最佳答案

查看节点生成的位置:

node.position = CGPointMake(frame.size.width + playerTexture!.size().width, 0)

然后在此基础上将玩家移动到节点的位置

let x = self.frame.size.width / 4
let y = CGRectGetMidY(self.frame)
playerNode!.position = CGPointMake(x, y)

这个可怜的家伙远远超出了屏幕空间。

关于ios - SpriteNode 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36271572/

相关文章:

ios - 在 viewWillAppear 中加载 GeoFire 查询的用户位置数据

iOS UIBackgroundMode 远程通知不适用于 4G

ios - 如何在 inputView 中设置默认日期值

swift - 从 Collection View 中查看和弹出时出错

swift - 如何使用自定义类型存储和检索变量

swift - 无法使用类型为 'SKSpriteNode.init' 的参数列表调用 '(texture: SKTexture, color: UIColor, size: CGSize, () -> ())'

swift spritekit 游戏,当我向敌人射击时,有时子弹会穿过敌人,我该如何解决这个问题?

swift - 多个 SKSpriteNode 的 SpriteKit 多个 SKActions - 等待所有完成

ios - 在 Swift 中将 AnyObject 向下转换为 Int(使用 Sprite Kit)

ios - Swift 3 - 有条件的扩展表格 View 单元格高度