#include "DrawingCanvas.h"
using namespace cocos2d;
bool DrawingCanvas::init()
{
if(!Node :: init())
{
return false;
}
drawnode = DrawNode::create();
this->addChild(drawnode);
background = LayerColor::create(Color4B(255,255,255,255));
this->addChild(background);
return true;
}
void DrawingCanvas::onEnter()
{
Node::onEnter();
Size visible = CCDirector::getInstance()->getVisibleSize();
this->setContentSize(visible);
drawnode->setContentSize(visible);
setupTouchHandling();
}
void DrawingCanvas::setupTouchHandling()
{
static Vec2 lastTouchPos,touchPos;
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = [&](Touch* touch, Event* event)
{
lastTouchPos = drawnode->convertTouchToNodeSpace(touch);
lastTouchPos = touchPos;
CCLOG("last %f %f\n",lastTouchPos.x,lastTouchPos.y);
return true;
};
touchListener->onTouchMoved = [&](Touch* touch, Event* event)
{
touchPos = drawnode->convertTouchToNodeSpace(touch);
CCLOG("now %f %f\n",touchPos.x,touchPos.y);
drawnode->drawSegment(lastTouchPos, touchPos, 4.0f*CC_CONTENT_SCALE_FACTOR(), Color4F(0.0f, 0.0f, 0.0f, 1.0f));
};
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, this);
}
Hey, the drawsegment call dosent seem to work . I also tried using just 4.0f as radius parameter.
Hey, the drawsegment call dosent seem to work . I also tried using just 4.0f as radius parameter.