0

i hope i'm not missing something.I'm trying to run SKAction on my SKShapeNode inside my update method , i made a flag check that i will only enter once to the "if" statment , it's working on the DidMoveToView method but dosent on the update or in the DidSymulatedPhyisics Method, any ideas why? My Node : // created path before works fine

 var step = SKShapeNode(path: pathtodraw2)
        step.fillColor = SKColor.whiteColor()
        step.position = CGPoint(x: 0, y: self.frame.midY)
        step.physicsBody = SKPhysicsBody(edgeChainFromPath: pathtodraw2)
        step.physicsBody?.affectedByGravity = false
        step.physicsBody?.dynamic = true
        self.addChild(step)

SKaction :

var movedown = SKAction.moveToY(324, duration: 5)
                step.runAction(movedown)

UPDATE : i even removed it from the if statment and put the SKAction in the top of the update method m and still dosent work . and i place it in thr didMoveToView it's working, no clue why The full update method :

if abs(circle.physicsBody!.velocity.dx) < 5 && abs(circle.physicsBody!.velocity.dy) < 5 && ismoved == true //check if the object stopped moving (not the one im trying to move down)
        {
            ismoved = false
            circle.physicsBody?.velocity = CGVectorMake(0, 0)
            self.userInteractionEnabled = true
            if circle.position.y > 100 && falloff == false { //checking if the second object above the first object **working fine used breakpoint* and it enter inside the statment
                println("asd"   )
                var movedown = SKAction.moveToY(324, duration: 5) //trying to move it down
                step.runAction(movedown) //trying to move it down
                falloff = true
            }
        }
        if abs(circle.physicsBody!.velocity.dx) > 1.4 && ismoved == false{ //check if the object start moving (not the only im trying to move down)
            ismoved = true
        }
  • 1
    What is the conditional you have in your `update` method? I'm not certain why you would need it there to prevent the code from running twice, as `update` will only be called once per frame. – Andrew Monshizadeh Jan 06 '15 at 03:06
  • @AndrewMonshizadeh i made a Boolean if statment that when it enters in once he wont be able to enter that again , but this way or another it's just dosent work inside the update method.. any ideas? – Aamenta straous Jan 06 '15 at 09:21
  • @Aamentastraous Please update the question with the code from the update method. – ZeMoon Jan 06 '15 at 09:25
  • Please explain "not working" and post *all* the code that's relevant in this context, including the if statement and every place where you make changes that could affect the condition. Most likely you end up not running the action at all, or you run it every time update runs, deadlocking it. – CodeSmile Jan 06 '15 at 13:49
  • Also, set a breakpoint and step through the code. See Xcode debugging guide. It's strongly recommended that any developer writing code knows how to use the basic debugging features. – CodeSmile Jan 06 '15 at 13:50
  • Okay, so to be sure I understand this, you start the node at `y == 0`. Then in `didMoveToView` you add the `SKAction` that moves the node to `y == 324` over 5 seconds. Then in your `update` method you want to try and move it to `y == 324` again? It may not look like it is running, but it probably is because you are trying to move it to the same spot it currently is in. – Andrew Monshizadeh Jan 06 '15 at 18:37
  • @AndrewMonshizadeh no no , even if my node is at y==0 and im putting a skaction in the update method to move him to 324 it wont work,but if i put the skaction inside the didmovetoview it works perfectly , same code.. i dont know wth is going on lol – Aamenta straous Jan 06 '15 at 18:46

0 Answers0