gpt4 book ai didi

ios - EXC_BAD_ACESS 在 iOS8 上的 SpriteKit 中崩溃

转载 作者:可可西里 更新时间:2023-11-01 02:16:57 27 4
gpt4 key购买 nike

我在尝试更改 SKSpriteNode 的位置时遇到了一个非常奇怪的崩溃。此崩溃发生在 iOS8 而不是 iOS9。

// 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()

}

当我尝试设置位置 (fewerColorsPowerupIcon.position) 时发生崩溃,这是崩溃消息:

Thread 1: EXC_BAD_ACCESS(code=EXC_I386_GPFLT)

如果我在设置节点位置后放置 .removeFromParent() 代码段,仍然会发生此崩溃。

最佳答案

我认为如果你删除 Sprite ,你将无能为力。

所以尝试这样做:

let spriteCopy =  fewerColorsPowerupIcon.copy()

// place the ball of the screen so that we can bring it on later
spriteCopy.position = CGPointMake((width * -0.1) , (height * -0.1))

// set the size of the icon
spriteCopy.xScale = scaleFactor
spriteCopy.yScale = scaleFactor

// add it the scene
self.addChild(spriteCopy)

或者您可以先在场景中添加,然后更改属性:

// remove the ball from its current parent
fewerColorsPowerupIcon.removeFromParent()

// add it the scene
self.addChild(fewerColorsPowerupIcon)

// 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

关于ios - EXC_BAD_ACESS 在 iOS8 上的 SpriteKit 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37124270/

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