How to implement horizontal and vertical scroll in box2d world properly?
I have implemented horizontal scroll, but vertical scroll making trouble, and the trouble is difficult to explain. So I can scroll scene
vertically, and horizontally, if that is been done from the scene's origin, i.e ccp(0,0). But when Scrolling towards X have been done, and been paused in the middle, then if i scroll it vertically, it actually scroll diagonally, back to origin(x), and new position of y.
IF SOMEONE HAVE GOT MY QUESTION THEN HERE IS THE ANSWR FOR HIM,
//NAVIGATION TOWARDS X AND Y WhenEver and how ever you want
if (abs(diffX) > abs(diffY))
{
CCLOG(@"yScrlFlag=%d",yScrlFlag);
if(diffX > 0)
{
xScrlFlag=1;
[self.parent runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/250) position:ccp((-3112-self.position.x),self.parent.position.y)]];
}
else
{
[self.parent runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/250) position:ccp(0,self.parent.position.y)]];
xScrlFlag=0;
}
}
else
{
if (1)
{
if(diffY < 0)
{
yScrlFlag=1;
//CCLOG(@"\n nodePosition.x=%f \n nodePosition.y=%f",nodePosition.x,nodePosition.y);
[self.parent runAction:[CCMoveTo actionWithDuration:(-(-500-self.parent.position.y)/250) position:ccp(self.parent.position.x,(-self.position.y))]];
}
else
{
yScrlFlag=0;
[self.parent runAction:[CCMoveTo actionWithDuration:(-(-500-self.parent.position.y)/250) position:ccp(self.parent.position.x,0)]];
}
CCLOG(@"yScrlFlag=%d",yScrlFlag);
}
}
精彩评论