Skip to content

Instantly share code, notes, and snippets.

@layerssss
Created August 16, 2014 05:54
Show Gist options
  • Save layerssss/b9f2ee5441294f2d522f to your computer and use it in GitHub Desktop.
Save layerssss/b9f2ee5441294f2d522f to your computer and use it in GitHub Desktop.
flowing text for cocos2d-js labels
var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
this._super();
var size = cc.director.getWinSize();
var helloLabel = new FlowLabel(100, "Lorem ipsum dolor sit amet, consectetur adipisicing elit.", "Arial", 24);
helloLabel.x = size.width / 2;
helloLabel.y = size.height / 2;
this.addChild(helloLabel, 5);
return true;
}
});
var FlowLabel = cc.LabelTTF.extend({
_flowText: null,
ctor: function (textSpeed, text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
this._textSpeed = textSpeed;
this._super('', fontName, fontSize, dimensions, hAlignment, vAlignment);
this.setString(text);
},
setString: function(text){
this._flowText = text;
this.runAction(cc.actionTween(this._flowText.length * this._textSpeed * 0.001, "flowOffset", 0, this._flowText.length));
},
updateTweenAction: function(value, key){
if(key == 'flowOffset'){
cc.LabelTTF.prototype.setString.call(this, this._flowText.substring(0, value));
}
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment