AS3:在奇怪的时间添加动态添加的内容
我在通过一定时间间隔添加动态内容时遇到问题。内容正在添加到屏幕上,但 X 位置以及补间似乎完全超出了接收器范围。
下面是间隔为 100 毫秒时的屏幕截图,效果最好。应用程序需要以 200 毫秒的速度运行(其中错误不太明显,但线条仍然偶尔太接近,大约每 4 次一次)。
可以看出,定位之间存在明显的差异。对于少数人来说它仍然很好,然后发生变化,再次变化,最后又恢复到原来的样子。
这是我控制此部分的代码:
function XYZ(){
Score = 90
var timeBefore = Score
if(timeBefore <= 2.4){
timeBefore = 2.5
Score = "2.5"
}
else if(timeBefore > 75){
timeBefore = 2.5
Score = "2.5"
}
trace(timeBefore)
var signInterval:uint = setInterval (addThis, 100);
var finishInterval:uint = setInterval (checkThis, timeBefore*200);
MCArray.push(signInterval), MCArray.push(finishInterval)
}
function addThis(){
trace("Adding this!")
timeElap++
var floorNum:sign = new sign
//floorNum.visible = false
floorNum.y = 325
floorNum.x = 0 - floorNum.width
floorNum.dtf_num.text = timeElap+""
addChildAt(floorNum, 1)
trace(stage.stageWidth+floorNum.width)
trace(floorNum.width)
TweenMax.to(floorNum, 1.5, {x:stage.stageWidth+floorNum.width, ease:Linear.easeNone})
floorSigns.push(floorNum)
}
任何人对导致这种情况发生的原因有任何想法吗?
注意:200 和 300 毫秒也会发生这种情况,尽管不太明显。
I am having an issue with adding dynamic content through an interval. The content is being added to the screen, but the X position, as well as the tween, seem to be completely out of sink.
The below is a screenshot when the interval is at 100 milliseconds, as it shows it best. The application needs to work at 200 milliseconds (where the error is not as clear, but the lines are still occationally too close, roughly every 4th).
As can be seen, there is a clear discrepancy between positioning. It remains fine for a few, then changes, changes again and then finally reverts back to what it was.
Here is my code that controls this section:
function XYZ(){
Score = 90
var timeBefore = Score
if(timeBefore <= 2.4){
timeBefore = 2.5
Score = "2.5"
}
else if(timeBefore > 75){
timeBefore = 2.5
Score = "2.5"
}
trace(timeBefore)
var signInterval:uint = setInterval (addThis, 100);
var finishInterval:uint = setInterval (checkThis, timeBefore*200);
MCArray.push(signInterval), MCArray.push(finishInterval)
}
function addThis(){
trace("Adding this!")
timeElap++
var floorNum:sign = new sign
//floorNum.visible = false
floorNum.y = 325
floorNum.x = 0 - floorNum.width
floorNum.dtf_num.text = timeElap+""
addChildAt(floorNum, 1)
trace(stage.stageWidth+floorNum.width)
trace(floorNum.width)
TweenMax.to(floorNum, 1.5, {x:stage.stageWidth+floorNum.width, ease:Linear.easeNone})
floorSigns.push(floorNum)
}
Anyone with any ideas as to what is causing this to happen?
Note: It also happens with 200 and 300 milliseconds, although less prominent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
setInterval()
和setTimer()
并不像您想象的那么精确。它们充其量只是向 avm 提示您何时希望运行某个函数。 这是一篇关于 JavaScript 的文章,但也适用于 ActionScript。您将需要改变您的架构和解决问题的方式。您想要创建一个
ENTER_FRAME
处理程序,然后使用getTimer()
来确定经过了多少时间,以及需要创建/定位和安排的内容。setInterval()
andsetTimer()
aren't nearly as precise as you might think they are. They are, at best, hints to the avm of when you would like a function to run. Here is a article that is about JavaScript but is applicable to actionscript as well.You will need to change your architecture and the way that you are approaching the problem. You want to create an
ENTER_FRAME
handler and then usegetTimer()
to determine how much time is elapsed, and what you need to create/position and schedule.