滚动时场景的荒谬和生涩的运动
当场景移动时,它会以一种荒谬和生涩的方式移动(有时并不总是),从而导致刺激。以下代码用于移动场景:
//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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 CCFollow,而不是手动执行所有操作:
CCFollow
Try CCFollow instead of doing everything manually:
CCFollow