Hello,
Has anyone been able to run this code (http://build-failed.blogspot.com.es/2012/08/freehand-drawing-with-cocos2d-x-and.html )in v3.0? It works ok in v2.2 but when I translate to v3.0 I have problems. See the picture, when I move the finger ‘onTouchesMoved’ don’t paints all the path.
I think the problem it’s in ccTouchesMoved, this is the original:
`void HelloWorld::ccTouchesMoved(CCSet* touches, CCEvent* event){
CCTouch *touch = (CCTouch *)touches->anyObject();
CCPoint start = touch->locationInView();
start = CCDirector::sharedDirector()->convertToGL(start);
CCPoint end = touch->previousLocationInView();
end = CCDirector::sharedDirector()->convertToGL(end);
target->begin();
float distance = ccpDistance(start, end);
for (int i = 0; i < distance; i++){
float difx = end.x - start.x;
float dify = end.y - start.y;
float delta = (float)i / distance;
brush->setPosition(
ccp(start.x + (difx * delta), start.y + (dify * delta)));
brush->visit();
}
target->end();
}
`
And this is the code in V3.0:
`void HelloWorld::onTouchesMoved(const std::vector< Touch * > &touches, Event* event){
Touch* touch = touches[0];
Point touchLocation = touch->getLocation();
// get start & end location
Point start = touch->getLocationInView();
Point end = touch->getPreviousLocationInView();
// get corrected location
start = Director::getInstance()->convertToGL(start);
end = Director::getInstance()->convertToGL(end);
// draw line on the canvas
target->begin();
float distance = end.getDistance(start);
//float distance = ccpDistance(start, end);
for (int i = 0; i < distance; i++){
float diffX = end.x - start.x;
float diffY = end.y - start.y;
float delta = (float)i / distance;
brush->setPosition(Point(start.x + (diffX * delta), start.y + (diffY * delta)));
brush->visit();
}
target->end();
}`
Sorry for my English…
Captura de pantalla 2014-02-25 a la(s) 01.15.17.png (57.0 KB)