Swift SpriteKit:线程1:addChild上的EXC_BAD_ACCESS?我做错了什么?

时间:2015-09-05 23:25:29

标签: swift sprite-kit

我有一个游戏,当你死了,你点击,游戏应该重新启动,但每当我点击重新启动它给我这个(见上文)错误。提前致谢(:

这是我的代码:

class MCTFruitGen: SKSpriteNode {
    var generationTimer: NSTimer!
    var fruits = [MCTFruit]()
    var fruitTracker = [MCTFruit]()

    func startGeneratingFruitEvery(seconds: NSTimeInterval) {
        generationTimer = NSTimer.scheduledTimerWithTimeInterval(seconds, target: self, selector: "generateFruit", userInfo: nil, repeats: true)
    }

    func stopGenerating() {
        generationTimer?.invalidate()
    }

    func generateFruit() {
        var scale: CGFloat
        let rand = arc4random_uniform(2)
        if rand == 0 {
            scale = -1.0
        } else {
            scale = 1.0
        }

        let strawberry = MCTFruit()
        strawberry.position.x = size.width/2 + strawberry.size.width/2
        strawberry.position.y = scale * (NMCGroundHeight/160 + strawberry.size.height)

        self.fruits.append(strawberry)
        fruitTracker.append(fruits)
        addChild(strawberry) // line that gives me the error
    }

    func stopFruit() {
        stopGenerating()
        for fruit in fruits {
            fruit.stopFruitMoving()
        }
    }
}

1 个答案:

答案 0 :(得分:0)

尝试使用@Override public void onBindViewHolder(CategoriesViewHolder categoriesViewHolder, final int i) { final Categories ci = categoriesList.get(i); categoriesViewHolder.title.setText(categoriesList.get(i).title); categoriesViewHolder.category_title.setText(categoriesList.get(i).category_title); //categoriesViewHolder.categori_img.setImageResource(categoriesList.get(i).photoId); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // launch activity by Categories } }); } 代替SKAction来生成SpriteKit中的水果或任何计时事件。例如

NSTimer