通过本节课,我学到了如何使节点进行旋转和缩放。主要是通过node.setScale()和node.setRotation()。
我通过查阅官网API。得知:setScale的缩放因子将会乘以该节点和它子节点的宽,高和深度。setRotation设置节点的旋转(angle)角度。0 是默认的旋转角度。 负数顺时针旋转节点,正数逆时针旋转节点。以上是我通过查阅资料得知的。下面附上部分核心代码:
this._super();
var size = cc.winSize;
var logo = new cc.Sprite(res.HelloWorld_png);
logo.setTag(100);
logo.setPosition(size.width/2,size.height/2);
this.addChild(logo);
//添加按钮
var itemFangda = new cc.MenuItemFont("放大",this.FangdaCallback,this);
itemFangda.x = size.width/3-500;
itemFangda.y = size.height/2 - 100;
var itemSuoxiao = new cc.MenuItemFont("缩小",this.SuoxiaoCallback,this);
itemSuoxiao.x = size.width/2 - 200;
itemSuoxiao.y = size.height/2 - 100;
var itemRotate = new cc.MenuItemFont("旋转",this.RotateCallback,this);
itemRotate.y = size.height/2 - 100;
itemFangda.setFontName("黑体");
itemSuoxiao.setFontName("黑体");
itemRotate.setFontName("黑体");
itemFangda.setFontSize(50);
itemSuoxiao.setFontSize(50);
itemRotate.setFontSize(50);
var menu = new cc.Menu(itemFangda,itemSuoxiao,itemRotate);
this.addChild(menu);
return true;
FangdaCallback:function(){
var Fangda = this.getChildByTag(100);
Fangda.setScale(1.1);
},
SuoxiaoCallback:function(){
var Suoxiao = this.getChildByTag(100);
Suoxiao.setScale(0.9);
},
RotateCallback:function(){
var Rotate = this.getChildByTag(100);
Rotate.setRotation(45);
}
最后附上作业链接:
http://www.cocoscvp.com/usercode/2016_04_17/921cf63df73f0a476a6846505b75ea7ddc9a9055/