如何在光标悬停在屏幕边缘附近时使图像移动
我需要为学校做这个项目,但我错过了这一件事。我正在使用actionscript3,并且有一个房间的全景图,只要鼠标光标悬停在屏幕边缘附近,我就想移动/滑动(左和右)。我还想循环播放该图像,以便您可以永远滑动它:)
我试图为此找到一个脚本,但显然语言障碍对我来说太大了。
I need to do this project for school and I'm missing this one thing. I'm working in actionscript3 and have a panoramic picture of a room, that I'd like to move/slide(left and right) whenever the mouse cursor hovers near the edge of the screen. I'd also like to loop that image, so that you could slide it for eternity :)
I tried to find a script for that but apparently the language barrier is too much for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先考虑逻辑,然后尝试实现它:)
首先,您需要为图像设置一个容器,为了使该图像循环,您可以添加相同的图像
要测试这一点,您可以设置一个输入帧事件侦听器它将负责沿一个或另一个方向移动容器 x
总而言之,您只需要两个图像,并且一旦一个图像离开屏幕,您就不断交换位置。
当您让这部分工作时,您需要参考容器的位置计算出鼠标位置。
例如,为了让容器以最大速度向右移动,你需要 mouseX 值接近 0,为了让容器不移动,mouseX 值应该等于 stage.stageWidth/2 ,即中心为了使容器以最大速度向左移动,mouseX 值应为 stage.stageWidth。
这样,您只需制定一个公式即可根据这些值更改容器移动的速度和方向。方向会根据正值或负值而改变,速度会根据鼠标相对于屏幕中心的距离而减小或增加。
然后,在您的输入帧事件侦听器中,您将更改为:
这应该可以帮助您开始;)
Think of the logic first then have a go at implementing it :)
First you need to set a container for you image , in order for this image to loop , you can add the same image
To test this you can set an enter frame event listener that would take care of moving the container x in one or the other direction
So altogether, you would simply need two images and you keep swapping position as soon as one gets out of the screen.
When you got this part working, you need to work out the mouse position in reference to the container's position.
For instance , in order for the container to go right at the maximum speed, you would need the mouseX value to be close to 0, for the container not to move , the mouseX value should be equal to stage.stageWidth/2 , the centre of the screen, and for the container to go left at the maximum speed, the mouseX value should be stage.stageWidth.
With that you just need to work out a formula that changes the speed as well as the direction of the container movement in relation to these values. the direction would change according to a positive or negative value and the speed would decrease or increase according to the distance of the mouse relative to the centre of the screen.
In your enter frame event listener you would then change to:
This should help you get started ;)