Permalink
Browse files

DrawNode fix 2:

Ignore previous patch.
DrawNode is compatible with JSB.
  • Loading branch information...
1 parent 81a29bd commit 2d5f56b20899a7dd3a342aceb96cfe48a1f95b4b @ricardoquesada ricardoquesada committed Dec 11, 2012
Showing with 15 additions and 12 deletions.
  1. +3 −10 cocos2d/Draw_Nodes/CCDrawNode.js
  2. +12 −2 cocos2d/physics_nodes/CCPhysicsDebugNode.js
View
13 cocos2d/Draw_Nodes/CCDrawNode.js
@@ -275,10 +275,10 @@ cc.DrawNode = cc.Node.extend({
},
/** draw a polygon with a fill color and line color */
- drawPolyWithVerts:function (verts, count, fillColor, width, borderColor) {
+ drawPoly:function (verts, fillColor, width, borderColor) {
var element = new cc._DrawNodeElement(cc.DRAWNODE_TYPE_POLY);
- element.verts = cc.DrawNode.convertVerts(verts);
- element.count = count;
+ element.verts = verts;
+ element.count = verts.length;
element.fillColor = fillColor;
element.borderWidth = width;
element.borderColor = borderColor;
@@ -395,10 +395,3 @@ cc._DrawNodeElement = function (type) {
cc.DRAWNODE_TYPE_DOT = 0;
cc.DRAWNODE_TYPE_SEGMENT = 1;
cc.DRAWNODE_TYPE_POLY = 2;
-cc.DrawNode.convertVerts = function (verts) {
- var ret = [];
- for (var i = 0; i < verts.length / 2; i++) {
- ret[i] = {x:verts[i * 2], y:verts[i * 2 + 1]};
- }
- return ret;
-};
View
14 cocos2d/physics_nodes/CCPhysicsDebugNode.js
@@ -34,6 +34,15 @@
as the private API may change with little or no warning.
*/
+// Helper. Converts an array of numbers into an array of vectors(x,y)
+cc.__convertVerts = function (verts) {
+ var ret = [];
+ for (var i = 0; i < verts.length / 2; i++) {
+ ret[i] = {x:verts[i * 2], y:verts[i * 2 + 1]};
+ }
+ return ret;
+};
+
cc.ColorForBody = function (body) {
if (body.isRogue() || body.isSleeping()) {
return cc.c4f(0.5, 0.5, 0.5, 0.5);
@@ -57,7 +66,7 @@ cc.DrawShape = function (shape, renderer) {
break;
case cp.PolyShape.prototype.collisionCode:
var line = cc.c4f(color.r, color.g, color.b, cc.lerp(color.a, 1.0, 0.5));
- this.drawPolyWithVerts(shape.tVerts, shape.getNumVerts(), color, 1.0, line);
+ this.drawPoly(cc.__convertVerts(shape.tVerts), color, 1.0, line);
break;
default:
cc.Assert(false, "Bad assertion in DrawShape()");
@@ -153,4 +162,5 @@ cc.PhysicsDebugNode.debugNodeForCPSpace = function (space) {
return null;
};
-cc.PhysicsDebugNode.create = cc.PhysicsDebugNode.debugNodeForCPSpace;
+cc.PhysicsDebugNode.create = cc.PhysicsDebugNode.debugNodeForCPSpace;
+

0 comments on commit 2d5f56b

Please sign in to comment.