如何在box2d世界中正确实现水平和垂直滚动? [英] How to implement horizontal and vertical scroll in box2d world properly?

查看:72
本文介绍了如何在box2d世界中正确实现水平和垂直滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了水平滚动,但是垂直滚动带来了麻烦,并且这种麻烦很难解释。因此,如果这是从场景的原点即ccp(0,0)完成的,那么我可以垂直和水平滚动 scene 。但是当完成向X的滚动并停在中间时,如果我垂直滚动它,它实际上会沿对角线滚动,回到原点(x),并返回y的新位置。

我知道理解起来很复杂,但是如何实现从向下滚动的位置垂直滚动。

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.

推荐答案

IF有人回答了我的问题,这里是他的答案,

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

这篇关于如何在box2d世界中正确实现水平和垂直滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆