c++cocos2d-xcocos2d-x-2.x

How do I draw a line using Cocos2D-X?


I have been playing around with Cocos2D-X on my computer, and I have got it to build the hello world program on all the devices I would like to be able to build it on.

I know how to make the program display a sprite, and display a label, but I have not been able just to get the program to draw a line. How can I draw a line in Cocos2D-X?


Solution

  • use void ccDrawLine(const CCPoint& origin, const CCPoint& destination) function declared in CCDrawingPrimitives.h

    Edit

    I've never tried using primitives myself. But as I know everything in cocos2d is rendered vis CCNode or it's subclass. So you must put your code inside draw method of some CCNode or it's subclass.