On Tue, Jun 22, 2010 at 7:32 AM, claudio canepa <[email protected]> wrote: > > > On Mon, Jun 21, 2010 at 6:37 PM, karanveer singh <[email protected]> > wrote: >> >> Ok, so I did the following : >> >> class Check(cocos.actions.Action): >> >> def step(self, dt): >> cell = test_layer.get_at_pixel(self.target.x, self.target.y) >> if(len(cell.properties) is not 0): >> if(cell.properties["block"] == True): >> self._done = True >> >> def stop(self): >> print "stopped" >> >> and i call it using the following in the sprite class: >> >> action = JumpBy( (200,0), 300, 1, duration=3) | Check() >> self.do(action) >> >> However, although it prints "stopped" when the sprite collides with >> the cell, it doesnt stop the action. It just print "stopped" 5 times >> and continues with the whole jump. >> >> > > 1) Your custom class Check should be calling the baseclass so that the > cocosnode.step can run detect the action Check terminates, something like: > def stop(self): > print 'stopped' > res = super(Check,self).stop() > return res > 2) With the actual code you will be stopping only the Check part; you want > to stop the composite action. > I'm in a hurry here, so I only will give some fast hints: > a) if you do > action = JumpBy( (200,0), 300, 1, duration=3) | Check() > worker_action = self.do(action) > > then you can stop the composite by > sprite.remove_action(worker_action) > b) You can arrange your Check.stop to use a) to stop the action. > Yes, that is not elegant. The interesting thing probably being... > Sorry, must go. > Tomorrow late I will be online again. > -- > claudio > > > > -- > You received this message because you are subscribed to the Google Groups > "cocos2d discuss" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/cocos-discuss?hl=en. >
Ok, so I added the following : In Check.step(): res = super(Check, self).step(dt) return res In Check.stop(): print "stop" self.target.remove_action(self.target.act) res = super(Check, self).stop() return res and in the sprite class : action = JumpBy( (200,0), 300, 1, duration=3) | Check() self.act = self.do(action) Still its going through the whole jump, but is printing "stop" whenever it hits the tile. -- You received this message because you are subscribed to the Google Groups "cocos2d discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
