Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
    
The code works for me. Is platform1Sprite a cc.Sprite? –  eazimmerman Oct 16 '12 at 14:25
    
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? –  ufo Oct 16 '12 at 14:30
1  
If you put your code into pastebin.com and link me, I will be glad to look it over for you. –  eazimmerman Oct 16 '12 at 14:40
    
pastebin.com/fGbW4LLH Lines 17 and 18 have the MoveTo action! –  ufo Oct 16 '12 at 21:02
    
are you sure you are not disabling schedule manager somewhere by mistake? –  Ali.S Oct 18 '12 at 9:08

1 Answer 1

up vote 2 down vote accepted

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();
},
share|improve this answer
    
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! –  ufo Oct 18 '12 at 6:59
    
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. –  eazimmerman Oct 18 '12 at 20:42
    
Also, if you delete the onEnter and onExit functions the code works. That's how the official example is coded; without the functions. –  eazimmerman Oct 18 '12 at 21:03
    
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! –  ufo Oct 22 '12 at 6:59
    
to schedule an update: in your init add "this.schedule(this.update);" then have a function like: "update:function (delta){}," –  eazimmerman Oct 30 '12 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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