Actionscript 3 无尽头道路的精确比例公式

Actionscript 3 无尽头道路的精确比例公式,actionscript-3,Actionscript 3,我正在制作一条从上到下的无休止的直线,并使用一个位图数据,我在多个瓷砖中使用它。通过使用计算其比例值的公式,这些瓷砖从上到下(比如说从屏幕的上到下)正确排列。第一个磁贴的比例值根据其位置计算,然后所有其他磁贴的比例值根据其先前的磁贴计算。这非常有效,除了当所有东西都循环时,我可以看到底部的瓷砖(第一块)的宽度比它应该的略大(大约5个像素太大)。当第一个磁贴离开屏幕时,它被发送回屏幕顶部,下一个磁贴扮演顶部磁贴的角色,等等。。。但是,由于道路的宽度略有扩大,因此在发生过渡时,道路的尺寸会略有增加。

我正在制作一条从上到下的无休止的直线,并使用一个位图数据,我在多个瓷砖中使用它。通过使用计算其比例值的公式,这些瓷砖从上到下(比如说从屏幕的上到下)正确排列。第一个磁贴的比例值根据其位置计算,然后所有其他磁贴的比例值根据其先前的磁贴计算。这非常有效,除了当所有东西都循环时,我可以看到底部的瓷砖(第一块)的宽度比它应该的略大(大约5个像素太大)。当第一个磁贴离开屏幕时,它被发送回屏幕顶部,下一个磁贴扮演顶部磁贴的角色,等等。。。但是,由于道路的宽度略有扩大,因此在发生过渡时,道路的尺寸会略有增加。这意味着我的公式很接近,但在计算第一块瓷砖的比例时有点错误。公式有什么问题,应该纠正什么

var speedFactor:Number = speed / _length;//size of screen top to bottom 
var bitmap:RoadTile = tiles[0]; 
bitmap.y += speedFactor * bitmap.y; //scaled speed      
var distance:Number = _length - bitmap.y;//calculate position and determine scale           
if(distance < 0)
{
    distance = _length + Math.abs(distance);
}
else
{
    distance = bitmap.y;
}           
var scale:Number = (distance / _length);    
bitmap.scaleX = bitmap.scaleY = scale;  
//scale is calculated but is slightly wrong.
var speedFactor:Number=speed/\u length//屏幕从上到下的尺寸
变量位图:RoadTile=tiles[0];
bitmap.y+=speedFactor*bitmap.y//标度速度
变量距离:Number=_length-bitmap.y//计算位置并确定刻度
如果(距离<0)
{
距离=_长度+数学绝对值(距离);
}
其他的
{
距离=位图.y;
}           
变量刻度:数字=(距离/_长度);
bitmap.scaleX=bitmap.scaleY=scale;
//刻度已计算,但有点错误。
您可以在此处看到结果:

请注意屏幕底部,其中道路的宽度略有变化,然后在移除顶部瓷砖并发送回起点时跳回到正常。 我现在用了一个面具,效果更好了,但那真的只是一个小技巧。 我还根据屏幕底部需要的宽度调整顶部瓷砖的比例,从而获得了更好的效果。但仍然不完美


我想我知道我遗漏了什么,我将继续努力:在公式中加入图形的角度。此处瓷砖侧面的角度为28(发动机使用不同侧面角度的瓷砖)。基本上,需要将角度添加到公式中,以便当顶部瓷砖向下移动时,根据屏幕底部的瓷砖宽度计算其新比例(该宽度必须始终相同,以便道路显示中不会出现跳跃)

确定最终得到准确的结果:

因此,从梯形图形组成的瓷砖开始,从上到下对齐(比例是根据之前的瓷砖计算的)。当然,要使一切无缝循环,您需要应用trig。 首先计算或定义2个梯形宽度(长宽度和短宽度)。然后使用磁贴的高度(不使用刻度)计算侧面的角度和所需的宽度(屏幕底部的磁贴循环在该位置必须始终具有的宽度)(在我的情况下,我使用的是中间注册的图形,但任何操作都可以):

接下来,在循环中,我们为顶部的互动程序增加了一些速度(无论您提出了什么系统,但互动程序有一点进步)


我没有展示如何对齐以下瓷砖,但这很简单,因为下一个瓷砖宽度需要是:图形宽度(upperWidth)*上一个瓷砖比例

可以发布图像吗?
var base:Number = (upperWidth - lowerWidth) / 2;
var length:Number = textureData.height;         
targetAngle = Math.atan(base / length)//this is our angle                   
oppositeAngle = Math.PI / 2 - angle;//opposite angle            
var side:Number = (length / 2) / Math.tan(oppositeAngle);           
endTargetWidth = upperWidth - (side * 2)//this is the width that the top tile must always have at the bottom of the screen.
var tilePos:Number = tile.y;//new position
var tileScale:Number = tile.scaleX;         
var targetPos:Number = (_length - tilePos) / tileScale;// where is the tile positioned according to the length and rescaled to 1? (bottom of screen)        
var sidetarget:Number = (textureData.height / 2) + targetPos;//(since I'm using middle registration)            
var side:Number = sidetarget / Math.tan(oppositeAngle);//that's it we get the extra length at scale 1
var projectedTileWidth:Number = lowerWidth + (side * 2);// this is the width of the tile at bottom of screen at scale 1
//we know the width the tile is gonna have (at scale 1) at bottom of screen
// and we know what width we need so let's divide and get our true correct scale value      
var scale:Number = endTargetWidth / projectedTileWidth
//now we apply that to our tile and the jumping issue is gone.