1
\$\begingroup\$

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));
this.creditLabel.runAction(MoveToAction);

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!

\$\endgroup\$
6
  • \$\begingroup\$ The code works for me. Is platform1Sprite a cc.Sprite? \$\endgroup\$ Oct 16, 2012 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, 2012 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\$ Oct 16, 2012 at 14:40
  • \$\begingroup\$ pastebin.com/fGbW4LLH Lines 17 and 18 have the MoveTo action! \$\endgroup\$
    – ufo
    Oct 16, 2012 at 21:02
  • \$\begingroup\$ are you sure you are not disabling schedule manager somewhere by mistake? \$\endgroup\$
    – Ali1S232
    Oct 18, 2012 at 9:08

1 Answer 1

2
\$\begingroup\$

I found out the problem! :)

In "credits.js" you need to change:

onEnter:function() {    
},

onExit: function() {
},

to

onEnter:function() {
    this._super();      
},

onExit: function() {
    this._super();
},

Hope this works for you!

-Edit-
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);
    this.resumeSchedulerAndActions();
},
\$\endgroup\$
5
  • \$\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, 2012 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\$ Oct 18, 2012 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\$ Oct 18, 2012 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, 2012 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\$ Oct 30, 2012 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .