CVP认证学习笔记--李天宇015实现绘图节点

前端之家收集整理的这篇文章主要介绍了CVP认证学习笔记--李天宇015实现绘图节点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本节课我学习了如何绘制节点,作业的内容是画一个五角星,运用的函数DrawNode.它继承自node。摘自:

http://api.cocos.com/cn/dd/d6a/classcocos2d_1_1_draw_node.html#details

下面是我的核心代码:首先我创建了一个专门画节点的类

var star = cc.DrawNode.extend({

ctor:function () {

this._super();

//这是第一个三角形

var points1 = [cc.p(140,360),

cc.p(90,200),

cc.p(190,200)];

this.drawPoly(points1,cc.color(255,255,0),1,0));

var points1_1 = [cc.p(140,240),200)];

this.drawPoly(points1_1,255),255));

//这是第二个三角形

var points2 = [cc.p(220,300),

cc.p(60,200)];

this.drawPoly(points2,0));

var points2_2 = [cc.p(220,

cc.p(170,260),200)];

this.drawPoly(points2_2,0));

return true;

}

});

然后在layer添加之前创建的五角星。

var HelloWorldLayer = cc.Layer.extend({

sprite:null,

ctor:function () {

this._super();

var bg = new cc.LayerColor(cc.color(255,800,450);

this.addChild(bg);

var star1 = new star();

this.addChild(star1);

var star2 = new star();

star2.setScale(0.3);

star2.setPosition(cc.p(200,100));

star2.setRotation(30);

this.addChild(star2);

var star3 = new star();

star3.setScale(0.3);

star3.setPosition(cc.p(330,150));

this.addChild(star3);

var star4 = new star();

star4.setScale(0.3);

star4.setPosition(cc.p(380,230));

star4.setRotation(-30);

this.addChild(star4);

var star5 = new star();

star5.setScale(0.3);

star5.setPosition(cc.p(200,350));

star5.setRotation(30);

this.addChild(star5);

return true;

}

});

var HelloWorldScene = cc.Scene.extend({

onEnter:function () {

this._super();

var layer = new HelloWorldLayer();

this.addChild(layer);

}

});

最后附上作业链接

http://www.cocoscvp.com/usercode/2016_04_20/6b72fac9c38202e2d5888bc13b942293dfae3c0e/

原文链接:https://www.f2er.com/cocos2dx/339519.html

猜你在找的Cocos2d-x相关文章