How to implement horizontal and vertical scroll in box2d world properly?

谁说我不能喝 提交于 2019-12-11 18:08:03

问题


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.
I know it's complicated to understand, but how can it be achieved to scroll it vertically from the position it have been scrolled down.


回答1:


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


来源:https://stackoverflow.com/questions/6197289/how-to-implement-horizontal-and-vertical-scroll-in-box2d-world-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!