【问题标题】:Alpha mask/texture physics body fatal error on launch - swift发射时的 Alpha 蒙版/纹理物理体致命错误 - 迅速
【发布时间】:2016-07-01 22:33:46
【问题描述】:

所以,我正在创建一个游戏,我正在尝试为英雄编写物理边界,这样他就不会在发布时从地板上掉下来,哈哈,所以我实现了我的场景,我正在尝试创建一个 alpha在我的“desertForeground”上掩盖纹理物理体,我没有收到任何错误,但是它一直在崩溃,我收到这个错误,调试并没有告诉我太多,它基本上只是说无效指令,但没有告诉我为什么是错的。 谁能帮帮我?我对快速编码物理体很陌生

import SpriteKit

enum BodyType:UInt32 {

case hero =    01

case bullet1 = 010

case enemy1 =  0100
case enemy2 =  01000
case enemy3 =  010000

case desertForegroundCase = 02
}
class GameScene: SKScene, SKPhysicsContactDelegate {

    let desertBackground = SKSpriteNode (imageNamed: "RZ- 
DesertBackground.png")
let desertForeground = SKSpriteNode (imageNamed: "RZ-
DesertForeground.png")
let desertgully = SKSpriteNode (imageNamed: "RZ-DesertGully.png")

     override func didMoveToView(view: SKView) {
       CreateScene()
}
    func CreateScene (){

    desertForeground.position = CGPoint(x: 570 , y: 102)
    desertForeground.size = CGSize (width: 1136, height: 200)
    desertForeground.zPosition = 1

    let desertForegroundTexture = SKTexture()
    let desertForegroundBody = SKPhysicsBody(texture: 
    desertForegroundTexture, size: CGSize(width: 1136, height: 200))

    desertForeground.texture = desertForegroundTexture

    desertForegroundBody.dynamic = true
    desertForegroundBody.affectedByGravity = false
    desertForegroundBody.allowsRotation = false
    desertForegroundBody.categoryBitMask = 
                   BodyType.desertForegroundCase.rawValue
    desertForegroundBody.contactTestBitMask = BodyType.enemy1.rawValue 
    | BodyType.enemy2.rawValue | BodyType.enemy3.rawValue  | 
      BodyType.soldierL.rawValue | BodyType.soldierT.rawValue

    desertForeground.physicsBody = desertForegroundBody
 }
 }

【问题讨论】:

    标签: sprite-kit game-physics mask skphysicsbody


    【解决方案1】:

    问题在于你如何填充desertForegroundTexture

    替换这个

    let desertForegroundTexture = SKTexture()
    

    有了这个

    let desertForegroundTexture = SKTexture(imageNamed: "YOUR_IMAGE_NAME")
    

    【讨论】:

      【解决方案2】:

      当您尝试从空纹理创建 physicBody 时出现问题:

      /**
           Creates a body from the alpha values in the supplied texture.
           @param texture the texture to be interpreted
           @param size of the generated physics body
           */
          @available(iOS 8.0, *)
          public /*not inherited*/ init(texture: SKTexture, size: CGSize)
      

      实际上,例如,如果您尝试像这样创建SKSpriteNode,则不会发生这种情况:

      let desertForegroundTexture = SKTexture()
      desertForeground = SKSpriteNode(texture: desertForegroundTexture, size:CGSize(width: 1136, height: 200))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-03
        • 1970-01-01
        相关资源
        最近更新 更多