public void ccTouchesMoved(List <CCObject> touches, CCEvent events) { foreach (var it in touches) { CCTouch touch = (CCTouch)it; CCPoint start = touch.locationInView(touch.view()); start = CCDirector.sharedDirector().convertToGL(start); CCPoint end = touch.previousLocationInView(touch.view()); // begin drawing to the render texture //m_pTarget->begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPointExtension.ccpDistance(start, end); if (distance > 1) { int d = (int)distance; Random rand = new Random(); for (int i = 0; i < d; i++) { float difx = end.x - start.x; float dify = end.y - start.y; float delta = (float)i / distance; m_pBrush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta)); m_pBrush.rotation = rand.Next() % 360; float r = (float)(rand.Next() % 50 / 50.0f) + 0.25f; m_pBrush.scale = r; /*m_pBrush->setColor(ccc3(CCRANDOM_0_1() * 127 + 128, 255, 255));*/ // Use CCRANDOM_0_1() will cause error when loading libtests.so on android, I don't know why. m_pBrush.Color = new ccColor3B { r = (byte)(rand.Next() % 127 + 128), g = 255, b = 255 }; // Call visit to draw the brush, don't call draw.. m_pBrush.visit(); } } } // finish drawing and return context back to the screen //m_pTarget->end(); }
public override void ccTouchesMoved(List <CCTouch> touches, CCEvent events) { foreach (var it in touches) { CCTouch touch = it; CCPoint start = touch.locationInView(touch.view()); start = CCDirector.sharedDirector().convertToGL(start); CCPoint end = touch.previousLocationInView(touch.view()); end = CCDirector.sharedDirector().convertToGL(end); // begin drawing to the render texture //m_target->begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPointExtension.ccpDistance(start, end); if (distance > 1) { int d = (int)distance; Random rand = new Random(); ; for (int i = 0; i < d; i++) { float difx = end.x - start.x; float dify = end.y - start.y; float delta = (float)i / distance; m_brush.position = new CCPoint(start.x + (difx * delta), start.y + (dify * delta)); m_brush.rotation = rand.Next() % 360; float r = ((float)(rand.Next() % 50) / 50.0f) + 0.25f; m_brush.scale = r; // Call visit to draw the brush, don't call draw.. m_brush.visit(); } } // finish drawing and return context back to the screen //m_target->end(false); } }