延迟加载无限滚动的背景在Flash CS5 / ActionScript 3的 [英] Lazy loading infinite scroll background in Flash CS5/ActionScript 3

查看:142
本文介绍了延迟加载无限滚动的背景在Flash CS5 / ActionScript 3的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的项目有一个巨大的背景图片(800px宽2585px高)慢慢滚动向上。

在,我用的是code处:的 http://www.ilike2flash.com/2010/08/endless-scrolling-background-in-as3.html

我修改了code向上滚动,但除了具有后的图像和循环的下一个之前偶尔会显示一个像素高的空行,一个奇怪的间歇性的缺陷,它确实似乎没有处理动态装好(我用几个不同的preloader脚本尝试,它打破了所有的人),这东西可能不会有一个问题,初步实现,但现在,我使用一个无情无义巨大的形象。

因此​​,我的问题:

一个。是否有免费的,基于Flash的无限滚动code左右浮动另一个位已经为延迟加载的背景对象的支持(比如,现有的背景砍伤6)?

乙。如果没有,任何想法如何,我可以修改上面的链接,这样做?

谢谢!我的AS3如下:

 停止();

//滚动运动的速度。
变种scrollSpeed​​:UINT = 2;

//这增加了该影片剪辑的两个实例搬上舞台。
VAR S1:ScrollBg =新ScrollBg();
VAR S2:ScrollBg =新ScrollBg();
的addChild(S1);
的addChild(S2);
setChildIndex(S1,0);
setChildIndex(S2,0);

//这个位置旁边的第一个第二个影片剪辑。
s1.y = 0;
s2.y = s1.height;

//添加事件监听器的阶段。
stage.addEventListener(Event.ENTER_FRAME,moveScroll);

//这个函数既移动到顶部的图像。如果第一和第二
//图像去通过阶段性顶部边界然后被转移到
//舞台的另一侧。
功能moveScroll(五:事件):无效{
  s1.y  -  = scrollSpeed​​;
  s2.y  -  = scrollSpeed​​;

  如果(s1.y< = -s1.height){
     s1.y = s1.height  -  scrollSpeed​​;
  }否则如果(s2.y< = -s2.height){
     s2.y = s2.height  -  scrollSpeed​​;
  }
}
 

解决方案

你好ændrew 链接有大约15行code。 它创建的对象的两个实例,它然后移动动作既1px的每一帧,并检查是否在第一剪辑出视图,此时它移动动画片段转移到其他剪辑的边缘。有没有很多的闪失......但如果​​我指出来了,我会说这是这里

 如果(s1.x< -s1.width){
  s1.x = s1.width;
}否则如果(s2.x< -s2.width){
  s2.x = s2.width;
}
 

应该是:(注意< = 而不是<

 如果(s1.x< = -s1.width){
  s1.x = s1.width;
}否则如果(s2.x< = -s2.width){
  s2.x = s2.width;
}
 

这将删除影片剪辑的几个像素的差距

据处理加载一个大的资产推移,只需添加滚动功能一旦加载。你可以看一下样品,在 http://drawlogic.com / 2007/09/20 / HOWTO-使用装载机式-AS3 / 但也有一堆人的。

The project I'm working on has a massive background image (800px wide by 2585px tall) that slowly scrolls upwards.

Before, I was using the code at: http://www.ilike2flash.com/2010/08/endless-scrolling-background-in-as3.html

I modified the code to scroll upwards, but in addition to having a weird intermittent bug that occasionally displays a pixel-tall blank line after the image and before looping the next, it really doesn't seem to handle dynamic loading well (I've tried using several different preloader scripts and it breaks all of them), something that may not have been an issue with the initial implementation but is now that I'm using a monstrously huge image.

Thus, my question:

a. Is there another bit of free, Flash-based infinite scroll code floating around that has support for lazy-loading background objects (Say, the existing background chopped in 6)?

b. If not, any idea how I could modify the above link to do so?

Thanks! My AS3 is as follows:

stop();

//The speed of the scroll movement.
var scrollSpeed:uint = 2;

//This adds two instances of the movie clip onto the stage.
var s1:ScrollBg = new ScrollBg();
var s2:ScrollBg = new ScrollBg();
addChild(s1); 
addChild(s2);
setChildIndex(s1, 0);
setChildIndex(s2, 0);

//This positions the second movieclip next to the first one.
s1.y = 0;
s2.y = s1.height;

//Adds an event listener to the stage. 
stage.addEventListener(Event.ENTER_FRAME, moveScroll); 

//This function moves both the images to top. If the first and second 
//images goes past the top stage boundary then it gets moved to 
//the other side of the stage. 
function moveScroll(e:Event):void{
  s1.y -= scrollSpeed;  
  s2.y -= scrollSpeed;  

  if(s1.y <= -s1.height){
     s1.y = s1.height - scrollSpeed;
  }else if(s2.y <= -s2.height){
     s2.y = s2.height - scrollSpeed;
  }
}

解决方案

howdy ændrew the link has about 15 lines of code. it creates two instances of the object, it then moves moves both 1px every frame and checks if the first clip is out of the view, at which point it moves the movieClip over to the edge of the other clip. There's not a lot of room for error... but if I had to point it out out, I'd say it's right here

if(s1.x < -s1.width){
  s1.x = s1.width;
}else if(s2.x < -s2.width){
  s2.x = s2.width;
}

should be: (notice the <= instead of <)

if(s1.x <= -s1.width){
  s1.x = s1.width;
}else if(s2.x <= -s2.width){
  s2.x = s2.width;
}

this removes the few pixels gap between the movieclips

As far as dealing with loading a big asset goes, just add the scroll function once it has loaded. you can look for a sample at http://drawlogic.com/2007/09/20/howto-using-loaders-in-as3/ but there are bunch of others.

这篇关于延迟加载无限滚动的背景在Flash CS5 / ActionScript 3的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆