如何创建视差自动滚动然后切换到鼠标控制事件?
stage.addEventListener(Event.ENTER_FRAME, loop, false);
function loop(e:Event): void
{
if(scene.x <= -10 && scene.x >= -9200)
scene.x -= (this.mouseX - 490) * speed;
{
if(scene.x > -10) scene.x = -10;
if(scene.x < -9200) scene.x = -9200;
}
}
这就是启动视差事件运行的所有代码。我正在使用来自 Layersmagazine.com 的 Lee Brimelow 的代码。
当您将鼠标向舞台左侧或右侧移动时,视差效果会很好地滚动,但我希望它在加载时自动启动视差效果,滚动一点然后停止并切换到由鼠标控制。
MouseOver 事件并不是真正有效,因为滚动不能很好地配合它。
stage.addEventListener(Event.ENTER_FRAME, loop, false);
function loop(e:Event): void
{
if(scene.x <= -10 && scene.x >= -9200)
scene.x -= (this.mouseX - 490) * speed;
{
if(scene.x > -10) scene.x = -10;
if(scene.x < -9200) scene.x = -9200;
}
}
So this is all the code that starts the Parallax event running. I'm using code from layersmagazine.com by Lee Brimelow.
The parallax effect scrolls along nicely when you move the mouse left or right of the stage, but what I would like it to do is start the Parallax effect automatically on load, scroll along for a bit then stop and switch to being controlled by the mouse.
MouseOver events aren't really effective as the scroll doesn't work well with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个计时器以从自动滚动切换到鼠标滚动。向 Enter Frame 事件添加一个事件侦听器,该事件每帧稍微调整滚动。当计时器到达时间时,删除 Enter Frame 事件侦听器,并启动鼠标滚动代码。
像...
Create a timer to switch from automatic to mouse scrolling. Add an event listener to the Enter Frame event that adjusts the scroll a little bit each frame. When the timer reaches its time, remove the Enter Frame event listener, and start the mouse scroll code.
Something like...