I'd like to run an action on a sprite using the MoveBy action. After lots of attempts, I can't achieve the goal... I have issues with the MoveBy in 2 different projects, so maybe I'm missing something in the setup... But I can't figure what!

The instruction is like this:

this.platform1Sprite.runAction(cc.MoveBy.create(1, cc.p(200, 0)));

I don't get any error, simply it doesn't work. platform1Sprite is a Sprite. But even with a LabelTTF it doesn't work:

var MoveToAction = cc.MoveTo.create(2.5, cc.p(size.width / 2, size.height / 2));

For this last snippet, you can view my complete code here: http://pastebin.com/fGbW4LLH.

The code I linked is somehow similar to the helloHTML5World official example, line 112 has the runAction method applied to a LabelTTF. The official example works, mine doesn't... I can't understand what's the difference!

  • \$\begingroup\$ The code works for me. Is platform1Sprite a cc.Sprite? \$\endgroup\$ – eazimmerman Oct 16 '12 at 14:25
  • \$\begingroup\$ Yes, it is. In the official COCOS2D-x forum they also said the code works. But I'm sure it doesn't! In the link to the forum there's the full code of a project that doesn't work. I'm using FF16, but even with Chrome it doesn't work (in 2 different computers). Suggestions? \$\endgroup\$ – ufo Oct 16 '12 at 14:30
  • 1
    \$\begingroup\$ If you put your code into pastebin.com and link me, I will be glad to look it over for you. \$\endgroup\$ – eazimmerman Oct 16 '12 at 14:40
  • \$\begingroup\$ pastebin.com/fGbW4LLH Lines 17 and 18 have the MoveTo action! \$\endgroup\$ – ufo Oct 16 '12 at 21:02
  • \$\begingroup\$ are you sure you are not disabling schedule manager somewhere by mistake? \$\endgroup\$ – Ali1S232 Oct 18 '12 at 9:08

I found out the problem! :)

In "credits.js" you need to change:

onEnter:function() {    

onExit: function() {


onEnter:function() {

onExit: function() {

Hope this works for you!

The reason actions were not running is because 1) the engine was not being notified of any of the objects in the layer and 2) the scheduler/actions were not being resumed for said layer.

CCNode.js's onEnter( ), called through CCLayer.js's onEnter( ):

onEnter:function () {
    this._isRunning = true;//should be running before resumeSchedule
    this._arrayMakeObjectsPerformSelector(this._children, cc.Node.StateCallbackType.onEnter);
|improve this answer|||||
  • \$\begingroup\$ Thank you... Unfortunately your solution seems wrong. Either the first snippet and the one after the EDIT don't work... Anyway, if you look at the HelloHTM5World official example there's nothing similar to what you posted... And that example works! Look at line 112 for LabelTTF's runAction method. Thank you very much for your help! \$\endgroup\$ – ufo Oct 18 '12 at 6:59
  • \$\begingroup\$ I zipped the code I used here: dropbox.com/s/3a1he4kdwel7k0h/cocos2dhtml5code.zip It was built from your pastebin code and it works in firefox and chrome. \$\endgroup\$ – eazimmerman Oct 18 '12 at 20:42
  • \$\begingroup\$ Also, if you delete the onEnter and onExit functions the code works. That's how the official example is coded; without the functions. \$\endgroup\$ – eazimmerman Oct 18 '12 at 21:03
  • \$\begingroup\$ Yes, you're right. The pastebin code referred to a slight different project. And without the onEnter and onExit methods (or using the super definition) it works. But the original project, that's here pastebin.com/bjNKcznE, didn't work with the line 167 uncommented... What if I want to schedule update??? I can't figure why it doesn't work! Thank you very much! \$\endgroup\$ – ufo Oct 22 '12 at 6:59
  • \$\begingroup\$ to schedule an update: in your init add "this.schedule(this.update);" then have a function like: "update:function (delta){}," \$\endgroup\$ – eazimmerman Oct 30 '12 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.