@H_
403_0@
本节课我学习了如何绘制节点,作业的
内容是画一个五角星,运用的
函数为
DrawNode.它继承自node。摘自:
@H_
403_0@
http://api.cocos.com/cn/dd/d6a/classcocos2d_1_1_draw_node.html#details
@H_
403_0@下面是我的核心
代码:首先我创建了一个专门画节点的类
@H_
403_0@var star = cc.DrawNode.extend({
@H_
403_0@ctor:function () {
@H_
403_0@this._super();
@H_
403_0@//
这是第一个三角形
@H_
403_0@var points1 = [cc.p(140,360),
@H_
403_0@cc.p(90,200),
@H_
403_0@cc.p(190,200)];
@H_
403_0@this.drawPoly(points1,cc.color(255,255,0),1,0));
@H_
403_0@var points1_1 = [cc.p(140,240),200)];
@H_
403_0@this.drawPoly(points1_1,255),255));
@H_
403_0@//
这是第二个三角形
@H_
403_0@var points2 = [cc.p(220,300),
@H_
403_0@cc.p(60,200)];
@H_
403_0@this.drawPoly(points2,0));
@H_
403_0@var points2_2 = [cc.p(220,
@H_
403_0@cc.p(170,260),200)];
@H_
403_0@this.drawPoly(points2_2,0));
@H_
403_0@return true;
@H_
403_0@}
@H_
403_0@});
@H_
403_0@然后在
layer里添加之前创建的五角星。
@H_
403_0@var HelloWorldLayer = cc.Layer.extend({
@H_
403_0@sprite:null,
@H_
403_0@ctor:function () {
@H_
403_0@this._super();
@H_
403_0@var bg = new cc.LayerColor(cc.color(255,800,450);
@H_
403_0@this.addChild(bg);
@H_
403_0@var star1 = new star();
@H_
403_0@this.addChild(star1);
@H_
403_0@var star2 = new star();
@H_
403_0@star2.setScale(0.3);
@H_
403_0@star2.setPosition(cc.p(200,100));
@H_
403_0@star2.setRotation(30);
@H_
403_0@this.addChild(star2);
@H_
403_0@var star3 = new star();
@H_
403_0@star3.setScale(0.3);
@H_
403_0@star3.setPosition(cc.p(330,150));
@H_
403_0@this.addChild(star3);
@H_
403_0@var star4 = new star();
@H_
403_0@star4.setScale(0.3);
@H_
403_0@star4.setPosition(cc.p(380,230));
@H_
403_0@star4.setRotation(-30);
@H_
403_0@this.addChild(star4);
@H_
403_0@var star5 = new star();
@H_
403_0@star5.setScale(0.3);
@H_
403_0@star5.setPosition(cc.p(200,350));
@H_
403_0@star5.setRotation(30);
@H_
403_0@this.addChild(star5);
@H_
403_0@return true;
@H_
403_0@}
@H_
403_0@});
@H_
403_0@var HelloWorldScene = cc.Scene.extend({
@H_
403_0@onEnter:function () {
@H_
403_0@this._super();
@H_
403_0@var layer = new HelloWorldLayer();
@H_
403_0@this.addChild(layer);
@H_
403_0@}
@H_
403_0@});
@H_
403_0@最后附上作业
链接:
@H_
403_0@
http://www.cocoscvp.com/usercode/2016_04_20/6b72fac9c38202e2d5888bc13b942293dfae3c0e/