如何在box2d世界中正确实现水平和垂直滚动?

发布于 2024-11-10 21:20:27 字数 188 浏览 2 评论 0原文

我已经实现了水平滚动,但垂直滚动却带来了麻烦,而且这个麻烦很难解释。所以我可以垂直和水平滚动场景,如果这是从场景的原点(即ccp(0,0))完成的。但是,当向 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年已逝 2024-11-17 21:20:27

如果有人有我的问题,那么这里是他的答案,

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

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);                       
                }
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文