Hi guys,
I started working on a sprite rotation using two touches and had to rewrite a part of my touch-related code. Most of the code worked well, however sometimes my pan-zoom layer moved away and zoomed far out.
After some debugging of my code, I realised that previous locations in touches were strange in these cases (this happened when only one of the touches have moved and the other stayed the same) so I examined the CCTouch::setTouchInfo function. I realised that it sets the m_prevPoint to m_point, which, when called for the first time, has not been set before and thus produces those “strange” values. To solve this, I have changed the code to
void setTouchInfo(int id, float x, float y)
{
m_nId = id;
m_prevPoint = m_point;
m_point.x = x;
m_point.y = y;
if (!m_startPointCaptured)
{
m_startPoint = m_point;
m_startPointCaptured = true;
// Since this is the initial call, set prev point to the current to prevent strange distance issues.
m_prevPoint = m_point;
}
}
At the moment I do not see any issues with this as the change only reflects the first call to this function. However, I was wondering whether there are any other solutions to this?
Thanks,
-Gregor