coco2d-js 節點的屬性和動做

官網:
http://cn.cocos2d-x.org/html


文檔:
http://cn.cocos2d-x.org/doc/jsdoc/symbols/cc.Node.html#onEnter html5

http://www.cocos2d-x.org/reference/html5-js/V3.0/index.htmlnode

=======================================================this

/*屬性*/
if(!true){
var sprite1 = new cc.Sprite(res.Sp1);
var sprite2 = new cc.Sprite(res.Sp1);
sprite1.attr({
x:200,//位置
y:200,
anchorX:0.5,//錨點
anchorY:0.5,
opacity:255 //透明度[0-255]
});
sprite1.scale = 0.5; //縮放比例
this.addChild(sprite1, 1, 1);spa

//打印屬性值
cc.log("x = " + sprite1.x, " y = " + sprite1.y);
cc.log("anchorX = " + sprite1.anchorX, " anchorY = " + sprite1.anchorY);
//打印屬性值
//.............................................................................................................................................
sprite2.attr({
x:400,//位置
y:200,
anchorX:0.5,//錨點
anchorY:0.5,
opacity:255 //透明度
});
sprite2.scale = 0.5; //縮放比例
//sprite2.scaleX = 0.5; //寬度縮放
this.addChild(sprite2, 1, 2);orm

sprite2.rotation = 40;//旋轉40度
//sprite2.rotationX = 40;//x軸旋轉40度,y軸同理htm

sprite2.color = cc.color(134,232,110);//設置node的顏色
sprite2.visible = true; //是否顯示ci

//打印屬性值
cc.log("tag = " + sprite2.getTag());
cc.log("x = " + sprite2.x, " y = " + sprite2.y);
cc.log("anchorX = " + sprite2.anchorX, " anchorY = " + sprite2.anchorY);
cc.log("color = " + sprite2.getColor());//rgb值
//打印屬性值
}文檔

//動做
if(true){
var sprite1 = new cc.Sprite(res.Sp1);
sprite1.attr({
x:200,//位置
y:200,
scale:0.5
});
this.addChild(sprite1, 2);get

var actionAry = [];
//moveTo,移動到新的座標
var moveto = new cc.MoveTo(1, cc.p(400, 200));
//sprite1.runAction(moveto);
//actionAry.push(moveto);

//moveBy,x, y相對增長
var moveby = new cc.MoveBy(1, cc.p(100, 100));
//sprite1.runAction(moveby);
actionAry.push(moveby);

//scaleto放大縮小
var scaleto = new cc.ScaleTo(1, 2);
var scaleto2 = new cc.ScaleTo(1, 1);
// var rp = new cc.RepeatForever(cc.sequence(scaleto, scaleto2));
// sprite1.runAction(rp);
//sprite1.runAction(cc.sequence(scaleto, scaleto2).repeatForever());
//scaleby
var scaleby = new cc.ScaleBy(1, 2);
//sprite1.runAction(scaleby);

//fadeto,透明度0-255
var fadeto = new cc.FadeTo(1, 200);
//sprite1.runAction(fadeto);
//fadein
var fadein = new cc.FadeIn(3, 255);
//sprite1.opacity = 0;
//sprite1.runAction(fadein);
//fadeout
var fadeout = new cc.FadeOut(1, 1);
//sprite1.runAction(fadeout);

//bezierto,拋物線
var bezier = [cc.p(200, 200), cc.p(400, 500), cc.p(600, 200)];
var bezierto = new cc.BezierTo(2, bezier);
//sprite1.runAction(bezierto);

//rotateto,旋轉
var rotateto = new cc.RotateTo(2, 90);
//sprite1.runAction(rotateto);
//rotateby
var rotateby = new cc.RotateBy(2, 360).repeatForever();
//sprite1.runAction(rotateby);
//sprite1.runAction(cc.spawn(bezierto, rotateby));

//fllow,跟隨節點
var childNode = new cc.Sprite(res.CloseNormal_png);
childNode.scale = 1;
// childNode.attr({
// x:100,
// y:100
// });
//this.addChild(childNode, 2);
//var followAction = new cc.Follow(sprite1);
//childNode.runAction(followAction);
//childNode.runAction(cc.follow(sprite1, cc.rect(0, 0, 100, 100)));

//blink閃爍
var blink = new cc.Blink(10, 100);
sprite1.runAction(blink);
setTimeout(function(){
blink.stop();//3秒後中止閃爍
}, 3000);

//sprite1.runAction(cc.sequence(actionAry));

相關文章
相關標籤/搜索