Rog Kil
Rog Kil

Reputation: 13

What is the property use of Node.remove_action in Pythonista?

I can’t seem to understand what key is that it required. Using Node,remove_all_actions just remove like everything. So I need something that could just stop specific action.

Here is the code I test on:

import sound
import random
import math
A = Action

class MyScene (Scene):
    def setup(self):
        self.node = SpriteNode('emj:Alien',parent=self,position=(self.size.w,self.size.h))
        self.node.run_action(A.move_to(0,0,10))
    
    def did_change_size(self):
        pass
    
    def update(self):
        pass
    
    def touch_began(self, touch):
        self.node.remove_actions() #<-----------What is the key here to stop self.node from moving. The error said “_Scene.Node hasn’t no attribute”
    
    def touch_moved(self, touch):
        pass
    
    def touch_ended(self, touch):
        pass

if __name__ == '__main__':
    run(MyScene(), show_fps=False)```

Upvotes: 1

Views: 120

Answers (1)

Mikael
Mikael

Reputation: 161

You can give the original action an arbitrary key that is then used to stop it.

from scene import *

class MyScene(Scene):
    def setup(self):
        self.node = SpriteNode('emj:Alien',parent=self,position=self.size/2)
        self.node.run_action(Action.move_to(0, 0, 10), 'my animation')
    
    def touch_began(self, touch):
        self.node.remove_action('my animation')

if __name__ == '__main__':
    run(MyScene(), show_fps=False)

Upvotes: 0

Related Questions