How to perform horizontal and vertical scrolling in the box2d world?

I applied a horizontal scroll, but the problem is with vertical scrolling, and the problem is hard to explain. Therefore, I can scroll scenevertically and horizontally if it was done from the beginning of the scene, i.e. Ccp (0,0). But when the scroll to X was done and was paused in the middle, then if I scroll it vertically, it actually scrolls diagonally, back to the beginning (x) and the new position y.
I know that this is difficult to understand, but how can this be achieved in order to scroll it vertically from the position in which it was scrolled down.

0
source share
1 answer

, , - ,

//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);                       
                }
            }
0

All Articles