打印

[编程] 图片随鼠标向左向右移动

有一张大图, 用遮罩只显示其中一部分. 然后鼠标向左移动时, 图片向右移动,显示左边图片.向右反之. 请高手提供一下参考的源码.谢谢.
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!
这种效果见多了
stop();
step=10;
stagew=Stage.width;
stageh=Stage.height;
_root.onEnterFrame=function(){
if(_root._xmouse>0&&_root._xmouse<stagew&&_root._ymouse>0&&_root._ymouse<stageh){
       image._x=image._x-(_root._xmouse-stagew/2)/step;}
}
做出来了.谢谢 只是有一点. 如果鼠标一直在左边或者右边. 图片会一直走, 直到走得好远好远. 这要什么方法解决呢.

[ 本帖最后由 songshengkonggu 于 2008-6-12 17:54 编辑 ]
再对image._x加个判断语句,
if(image._x<最左边的x){
image._x = 最左边的x
}else if(image._x>最右边的x){
image._x = 最右边的x
}

TOP

还在为头像烦恼?还在为不能关注好友动态烦忧?快来蓝色理想家园吧!
引用:
原帖由 libins 于 2008-6-12 18:21 发表
再对image._x加个判断语句,
if(image._x最右边的x){
image._x = 最右边的x
}
我放上去还是没有用. 我想问一下,"image._x最右边的x" 这个X应该写什么呢? 

我的场景的大小是200*400. 图片的大小是400*400.影片剪辑的名称为image
代码写在帧上.

stop();
step=10;
stagew=Stage.width;
stageh=Stage.height;
_root.onEnterFrame=function(){
if(_root._xmouse>0&&_root._xmouse<stagew&&_root._ymouse>0&&_root._ymouse<stageh){
       image._x=image._x-(_root._xmouse-stagew/2)/step;}
}


if(image._x<0){
image._x =0
}else if(image._x>200){
image._x = 200
}

我想问一下. 最左边的x和最右边的x指的是什么呢??

TOP

最左边的x指的是图片你所希望的它向左移时极限值
最右边就繁殖
你可以加一个trace(image._x)来判断你所需的这个X值


还有一个问题就是:
复制内容到剪贴板
代码:
_root.onEnterFrame=function(){
if(_root._xmouse>0&&_root._xmouse<stagew&&_root._ymouse>0&&_root._ymouse<stageh){
       image._x=image._x-(_root._xmouse-stagew/2)/step;}
if(image._x<0){
image._x =0
}else if(image._x>200){
image._x = 200
}
}
要改成这样

TOP

我太笨了. 还是没做出来. 麻烦帮我改一下吧.谢谢. 源文件我传上来.
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!

TOP

我刚才都把代码贴出来,你还是弄错
附件: 您所在的用户组无法下载或查看附件,您需要注册/登录后才能查看!

TOP

太感谢.

太感谢了! 终于看到想要的效果.呵呵.

[ 本帖最后由 songshengkonggu 于 2008-6-13 16:44 编辑 ]

TOP

还是不懂

TOP

估计你要补习下缓冲函数的写法了

TOP