标签:
记录一些coco简单的属性和动作,位置,锚点,透明度,大小,移动等
/*属性*/
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);
//打印属性值
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);
sprite2.rotation = 40;//旋转40度
//sprite2.rotationX = 40;//x轴旋转40度,y轴同理
sprite2.color = cc.color(134,232,110);//设置node的颜色
sprite2.visible = true; //是否显示
//打印属性值
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);
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));
标签:
原文地址:http://www.cnblogs.com/ajun/p/4278982.html