滚动时场景的荒谬和生涩的运动

发布于 2024-11-16 01:38:38 字数 3598 浏览 2 评论 0原文

当场景移动时,它会以一种荒谬和生涩的方式移动(有时并不总是),从而导致刺激。以下代码用于移动场景:

//NAVIGATION TOWARDS X AND Y WhenEver and how ever you want

            if (abs(diffX) > abs(diffY))    //Scroll in x
            {
                //CCLOG(@"yScrlFlag=%d",yScrlFlag);
                if(diffX > 0)
                {
                    xScrlFlag=1;
                    [self.parent runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/950)
                                                               position:ccp((-3112-self.position.x),self.parent.position.y)]];
                    [resetPosition setIsEnabled:YES];
                    [resetPosition runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/950) 
                                                                 position:ccp((3112+self.position.x+70),resetPosition.position.y)]];
                    //[self.parent.menuButton setIsEnabled:NO];
                }
                else
                {
                    xScrlFlag=0;                        
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/950) 
                                                               position:ccp(0,self.parent.position.y)]];
                    //[resetPosition setIsEnabled:YES];
                    [resetPosition runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/950) 
                                                                 position:ccp(141,resetPosition.position.y)]];
                }
            }
            else  //Scroll in y
            {                       
                if(diffY < 0)
                {
                    [resetPosition setIsEnabled:YES];
                    //CCLOG(@"MOVING PARENT BY=%f",(-self.position.y));
                    //CCLOG(@"self.parent.position BEFORE MOVE=(%f, %f)",self.parent.position.x,self.parent.position.y);
                    //CCLOG(@"resetPosition.position BEFORE MOVE=(%f, %f)",resetPosition.position.x,resetPosition.position.y);
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/650) 
                                                               position:ccp(self.parent.position.x,(-self.position.y))]];

                    //Working
                    [resetPosition runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/650) 
                                                                 position:ccp(resetPosition.position.x, 280-(-self.position.y))]];

                    //CCLOG(@"self.parent.position AFTER MOVE=(%f, %f)",self.parent.position.x,self.parent.position.y);
                    //CCLOG(@"resetPosition.position BEFORE MOVE=(%f, %f)",resetPosition.position.x,resetPosition.position.y);
                }
                else
                {   
                    //CCLOG(@"yScrlFlag");
                    yScrlFlag=0;
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/950) 
                                                               position:ccp(self.parent.position.x,0)]];

                    [resetPosition runAction:[CCMoveTo actionWithDuration:round(-(-300-self.parent.position.y)/949) 
                                                                 position:ccp(resetPosition.position.x,280)]];
                }

            }

我想要的是场景移动的所有时间平滑度。如代码所示,它在水平和垂直方向上移动场景。当场景中的一个(任何)sprite 被调动并且场景开始滚动时,就会出现基本问题。在这种情况下,它的行为也很不稳定(可能比正常情况更严重)。有什么建议吗?

When the scene moves, it moves (sometimes not always) in an absurd and jerky way that leads to irritation. The following code has been used to move the scene:

//NAVIGATION TOWARDS X AND Y WhenEver and how ever you want

            if (abs(diffX) > abs(diffY))    //Scroll in x
            {
                //CCLOG(@"yScrlFlag=%d",yScrlFlag);
                if(diffX > 0)
                {
                    xScrlFlag=1;
                    [self.parent runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/950)
                                                               position:ccp((-3112-self.position.x),self.parent.position.y)]];
                    [resetPosition setIsEnabled:YES];
                    [resetPosition runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/950) 
                                                                 position:ccp((3112+self.position.x+70),resetPosition.position.y)]];
                    //[self.parent.menuButton setIsEnabled:NO];
                }
                else
                {
                    xScrlFlag=0;                        
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/950) 
                                                               position:ccp(0,self.parent.position.y)]];
                    //[resetPosition setIsEnabled:YES];
                    [resetPosition runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/950) 
                                                                 position:ccp(141,resetPosition.position.y)]];
                }
            }
            else  //Scroll in y
            {                       
                if(diffY < 0)
                {
                    [resetPosition setIsEnabled:YES];
                    //CCLOG(@"MOVING PARENT BY=%f",(-self.position.y));
                    //CCLOG(@"self.parent.position BEFORE MOVE=(%f, %f)",self.parent.position.x,self.parent.position.y);
                    //CCLOG(@"resetPosition.position BEFORE MOVE=(%f, %f)",resetPosition.position.x,resetPosition.position.y);
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/650) 
                                                               position:ccp(self.parent.position.x,(-self.position.y))]];

                    //Working
                    [resetPosition runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/650) 
                                                                 position:ccp(resetPosition.position.x, 280-(-self.position.y))]];

                    //CCLOG(@"self.parent.position AFTER MOVE=(%f, %f)",self.parent.position.x,self.parent.position.y);
                    //CCLOG(@"resetPosition.position BEFORE MOVE=(%f, %f)",resetPosition.position.x,resetPosition.position.y);
                }
                else
                {   
                    //CCLOG(@"yScrlFlag");
                    yScrlFlag=0;
                    [self.parent runAction:[CCMoveTo actionWithDuration:(-(-300-self.parent.position.y)/950) 
                                                               position:ccp(self.parent.position.x,0)]];

                    [resetPosition runAction:[CCMoveTo actionWithDuration:round(-(-300-self.parent.position.y)/949) 
                                                                 position:ccp(resetPosition.position.x,280)]];
                }

            }

What I want is all time smoothness in the movement of scene. As the code shows, it moves the scene in both horizontal and vertical direction. And the basic problem occurs when one (any) sprite in the scene is mobilized, and the scene starts scrolling. It behaves in a jerky way in that case too (possibly more so than in the normal case). Any suggestions?

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

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

发布评论

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

评论(1

冷…雨湿花 2024-11-23 01:38:38

尝试使用 CCFollow,而不是手动执行所有操作:

CCFollow

Try CCFollow instead of doing everything manually:

CCFollow

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