Skip to content

DrawSegment not working on xcode  #5

@ramyas1609

Description

@ramyas1609
#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions