Can't runAction on cc.LabelTTF

Hi!
I’m a very newbie on COCOS2D-html5 and I’m trying to animate a cc.LabelTTF. I’m using the same template of the HelloWorld example, the difference is on the Layer definition. That is:

`var creditLayer = cc.Layer.extend({
creditLabel:null,

init:function(text) {
    this._super();

    var size = cc.Director.getInstance().getWinSize();

    this.creditLabel = cc.LabelTTF.create(text, "Arial", 38);
    this.creditLabel.setAnchorPoint(cc.p(0.5,0.5));
    this.creditLabel.setPosition(cc.p(size.width / 2, 0));
    this.addChild(this.creditLabel, 5);        

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

    this.creditLabel.scheduleUpdate();

    this.setTouchEnabled(true);   

    return true;
},

onEnter:function() {
},

onExit: function() {
},

});`

What am I missing?
Thank you very much!

Can someone help me? If you need more code or anything else just ask! Thank you again!

remove
this.creditLabel.scheduleUpdate();

I’m sorry De Meng! That was a misprint from some tests about the problem! But even without that line, the code doesn’t work!

Environment settings is right?

copy all HelloHTML5World project?

That’s the full example!

would you give me all code ?

That’s already all the code. I’m just developing an example of use. So the code is quite short!
I’ve tried with FF and Chrome!

Notice1:
Did you add js filename into cocos2d.js.

(function () {
var d = document;
var c = {
COCOS2D_DEBUG:2, //0 to turn debug off, 1 for basic debug, and 2 for full debug
box2d:false,
showFPS:false,
frameRate:60,
tag:‘gameCanvas’, //the dom element to run cocos2d on
engineDir:‘libs/cocos2d/’,
//SingleEngineFile:‘’,
appFiles:[
’src/resource.js’,
‘src/xxxxx.js’ //->add your js filename
]
};

Notice2:
all resource name were wrote into resource.js .

Notice1: Yes, the file is credits.js. The Label is showed in the canvas, but it doesn’t move with runAction.
Notice2: There aren’t resources in my project for now. Just a label…

Can you please try the project with your browser? What I’m trying to do is just to show a layer with a label that moves from the bottom to the center of the screen and then replace this layer with a different one, using a different label.

Matteo Bucchi wrote:

Hi!
I’m a very newbie on COCOS2D-html5 and I’m trying to animate a cc.LabelTTF. I’m using the same template of the HelloWorld example, the difference is on the Layer definition. That is:
>
`var creditLayer = cc.Layer.extend({
creditLabel:null,

init:function(text) {
    this._super();

    var size = cc.Director.getInstance().getWinSize();
    
    this.creditLabel = cc.LabelTTF.create(text, "Arial", 38);
    this.creditLabel.setAnchorPoint(cc.p(0.5,0.5));
    this.creditLabel.setPosition(cc.p(size.width / 2, 0));
    this.addChild(this.creditLabel, 5);        
    
  var MoveToAction = cc.MoveTo.create(2.5, cc.p(size.width / 2, size.height / 2));
  this.creditLabel.runAction(MoveToAction);

  this.creditLabel.scheduleUpdate();

    this.setTouchEnabled(true);   
    
  return true;
},

onEnter:function() {
},

onExit: function() {
},

});`
>
What am I missing?
Thank you very much!

run ok in FF and chrome.

<this.creditLabel = cc.LabelTTF.create(text, “Arial”, 38);
notice : text is not null .

maybe init() method can not be overloaded.

var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new Helloworld();
layer.init(); ->>>>>>>init(text)
this.addChild(layer);
}
});

I don’t think so. Even trying without the text parameter it doesn’t work…

`var creditLayer = cc.Layer.extend({
creditLabel:null,

init:function() {
    this._super();

    var size = cc.Director.getInstance().getWinSize();

    this.creditLabel = cc.LabelTTF.create(Math.random(), "Arial", 38);
    this.creditLabel.setAnchorPoint(new cc.Point(0.5,0.5));
    this.creditLabel.setPosition(new cc.Point(size.width / 2, 0));        

    var MoveToAction = cc.MoveTo.create(2, new cc.Point(size.width / 2, size.height / 2));
    this.creditLabel.runAction(cc.Spawn.create(MoveToAction));

    this.addChild(this.creditLabel, 5);
    this.setTouchEnabled(true);   

    return true;
},

onEnter:function() {
},

onExit: function() {
},

});

var creditsScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layerCreated = new creditLayer();
layerCreated.init();
this.addChild(layerCreated);

    var layerProgrammed = new creditLayer();
    layerProgrammed.init();
    this.scheduleOnce(function() {
        this.removeChild(layerCreated);
        this.addChild(layerProgrammed);
    }, 3.0);
},

});

`

De Meng wrote:

run ok in FF and chrome.

I’m using the last version of FF (16) and it doesn’t work for me. Also tryed with Chrome, but again MoveTo doesn’t work. I tryed with MoveBy, I tryed using a Sprite. The actions are not performed… I’m thinking about a bug, but if so why the tests work?
Anyway I should try with IE…

Hi, please remove the define of onEnter and onExit on creditLayer or add this.*super in it.
Here is the code which works well.
<pre>
var creditLayer = cc.Layer.extend {
this.*super();
var size = cc.Director.getInstance().getWinSize();
this.creditLabel = cc.LabelTTF.create(text, “Arial”, 38);
this.creditLabel.setAnchorPoint(cc.p(0.5,0.5));
this.creditLabel.setPosition(cc.p(size.width / 2, 0));
this.addChild(this.creditLabel, 5);
var MoveToAction = cc.MoveTo.create(2.5, cc.p(size.width / 2, size.height / 2));
this.creditLabel.runAction(MoveToAction);
//this.creditLabel.scheduleUpdate();
this.setTouchEnabled(true);
return true;
}

});

var MyScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new creditLayer();
this.addChild(layer);
layer.init(‘test for Matteo Bucchi’);
}
});

You’re right. It works.

Shun Lin 怎么修改cc.LabelTTF的颜色啊

var scoreLabel = cc.LabelTTF.create(“Score 0”, “Courier”, 20);
//scoreLabel.setColor(cc.c3(0,0,0)); //没效果
scoreLabel.setPosition(cc.p(150,450));