0
votes

I have run into this strange issue. I am adding an enemy(SKSpriteNode) from inside the GameScene didMove(to view: SKView) using addChild.

The enemy has been positioned to x:100, y: 100 and it appears correctly. I also have another animation , the completion of which I am adding another enemy at the same location . But the enemy appears at a different location.The completion block is as shown below.

    holeExplosion.runHoleExplosionAction {[unowned self] in
        //self.addEnemy(enemyCount: 1, hole: holeExplosion)
        var modEnemy: ParentEnemy? = nil
        modEnemy = Enemy1(imageNamed: "Zombie1Jump1.png", healthPower:30)

        print(" \(self.scene?.position.x)  \(self.scene?.parent) ")
        self.addChild(modEnemy!)
        modEnemy!.enemySpeed = self.enemy1Speed
        modEnemy!.name = "enemy1"

        modEnemy!.position = CGPoint (x: 100 , y: 100)
        modEnemy!.zPosition = 2
    }

Any help would be appreciated. Thanks.

1
"self" is not the scene, self is the explosion node, you need to add to the scene with self.scene.addChild(modEnemy!) - Knight0fDragon
I checked with self.scene.add it still shows at the same location. - vaishakh
what do you mean it "shows", position is relative to the parent, not absolute. if a parent is at 10, and a child is at 20, then in reality the child is at 30, but it will only show 20 - Knight0fDragon
Yes I had already checked that perspective. I did change the position of holeExpansion to check if the parent it is referring too is the holeExpansion and not scene. But change in holeExpansion position doesn't affect the position of enemy . It is not relative to the holeExpansion. - vaishakh

1 Answers

0
votes

Your enemy class have physicsBody delegate?? maybe you can see that first because if it has it, you have to search your isDynamic property. You can't have 2 bodies in the same space when the property is equal to true.