Near complex polygon verts not showing up, why?

Hello, just playing with cocos2dx, The vertices for drawing a polygon on a drawnode seems a bit random.

this works fine:

    	Vec2 vertices[] = 
	{ 
		Vec2(0,0),
		Vec2(100,100),
		Vec2(100,10), 
		Vec2(0,10),
	};

but the following doesn’t work: Why?

	Vec2 vertices[] = 
	{ 
Vec2(0,0),
Vec2(1,1),
Vec2(2,2),
Vec2(3,3),
Vec2(4,4),
Vec2(5,5),
Vec2(6,6),
Vec2(7,7),
Vec2(8,8),
Vec2(9,9),
Vec2(10,10),
Vec2(11,11),
Vec2(12,12),
Vec2(13,13),
Vec2(14,14),
Vec2(15,15),
Vec2(16,16),
Vec2(17,17),
Vec2(18,18),
Vec2(19,19),
Vec2(20,20),
Vec2(21,21),
Vec2(22,22),
Vec2(23,23),
Vec2(24,24),
Vec2(25,25),
Vec2(26,26),
Vec2(27,27),
Vec2(28,28),
Vec2(29,29),
Vec2(30,30),
Vec2(31,31),
Vec2(32,32),
Vec2(33,33),
Vec2(34,34),
Vec2(35,35),
Vec2(36,36),
Vec2(37,37),
Vec2(38,38),
Vec2(39,39),
Vec2(40,40),
Vec2(41,41),
Vec2(42,42),
Vec2(43,43),
Vec2(44,44),
Vec2(45,45),
Vec2(46,46),
Vec2(47,47),
Vec2(48,48),
Vec2(49,49),
Vec2(50,50),
Vec2(51,51),
Vec2(52,52),
Vec2(53,53),
Vec2(54,54),
Vec2(55,55),
Vec2(56,56),
Vec2(57,57),
Vec2(58,58),
Vec2(59,59),
Vec2(60,60),
Vec2(61,61),
Vec2(62,62),
Vec2(63,63),
Vec2(64,64),
Vec2(65,65),
Vec2(66,66),
Vec2(67,67),
Vec2(68,68),
Vec2(69,69),
Vec2(70,70),
Vec2(71,71),
Vec2(72,72),
Vec2(73,73),
Vec2(74,74),
Vec2(75,75),
Vec2(76,76),
Vec2(77,77),
Vec2(78,78),
Vec2(79,79),
Vec2(80,80),
Vec2(81,81),
Vec2(82,82),
Vec2(83,83),
Vec2(84,84),
Vec2(85,85),
Vec2(86,86),
Vec2(87,87),
Vec2(88,88),
Vec2(89,89),
Vec2(90,90),
Vec2(91,91),
Vec2(92,92),
Vec2(93,93),
Vec2(94,94),
Vec2(95,95),
Vec2(96,96),
Vec2(97,97),
Vec2(98,98),
Vec2(99,99),
Vec2(100,100),
		Vec2(100,10), 
		Vec2(0,10),
	};

I would like to be able to draw a polygon to be the ground eventually from left to right, and then also turn into a physics body too , The ground will eventually have mountains etc , so the polygon will have several points over the width of the screen. I would eventually cut it down so any on the same height are removed, but for now, i want to know why it wont draw?

How are you drawing these vertices?

drawNode->drawPolygon(vertices, 4, Color4F(1.0f,0.3f,0.3f,1), 3, Color4F(0.2f,0.2f,0.2f,1));

Thank for replying, if i do smaller, less verts, it is ok, as soon as i do more verts, for even a simple rectangle…nothing.

Change the second parameter 4 (which is the number of verts) to the actual number of verts, or let the compiler calculate it for you like this sizeof(vertices)/sizeof(vertices[0])

1 Like

There is a DrawNode example, also, in the Programmers Guide Samples. Chapter 2

1 Like