SKSpriteNodeの位置を変更しようとすると、非常に奇妙なクラッシュが発生します。このクラッシュはiOS8ではなくiOS9で発生します。iOS8のSpriteKitでEXC_BAD_ACESSがクラッシュする
// if the powerup is full, spawn the icon on screen
if orangeBallsCollected == numberOfBallsRequiredToActivatePowerup {
// add the powerup icon to the array of powerupiconsonscreen
powerupIconsOnScreen.append(fewerColorsPowerupIcon)
// set the lighting mask of the powerup icon so that we know what positon it is onscreen for alter
fewerColorsPowerupIcon.lightingBitMask = UInt32(powerupIconsOnScreen.count - 1)
// remove the ball from its current parent
fewerColorsPowerupIcon.removeFromParent()
print(fewerColorsPowerupIcon, fewerColorsPowerupIcon.parent, fewerColorsPowerupIcon.physicsBody, fewerColorsPowerupIcon.superclass)
// place the ball of the screen so that we can bring it on later
fewerColorsPowerupIcon.position = CGPointMake((width * -0.1) , (height * -0.1))
// set the size of the icon
fewerColorsPowerupIcon.xScale = scaleFactor
fewerColorsPowerupIcon.yScale = scaleFactor
// add it the scene
self.addChild(fewerColorsPowerupIcon)
// animate it moving down to the first avaliable position
let animation = SKAction.moveTo(CGPoint(x: width * 0.1, y: height * 0.1), duration: 0.5)
// run the animation!
fewerColorsPowerupIcon.runAction(animation)
// activate the poweurp
activateFewerColors()
}
I位置(fewerColorsPowerupIcon.position
)を設定しようとすると、クラッシュが発生し、これがクラッシュメッセージである:
スレッド1:EXC_BAD_ACCESS(コード= EXC_I386_GPFLT)
このクラッシュノードの位置を設定した後に.removeFromParent()
コードを置くと、やはりエラーが発生します。もはやそれへの強い参照がないかもしれないとすぐにremoveFromParent()
を呼び出すとその後
weak var fewerColorsPowerupIcon: Type!
、:fewerColorsPowerupIcon
のようなものを宣言していた場合
はあなただけnilにオブジェクトを設定する代わりに、親から削除しようとしています? –
lessColorsPowerupIconはどのように宣言されていますか? –
@LouFrancoオブジェクトは宣言されていますvar lessColorsPowerupIcon:SKSpriteNode! – Onglo