【问题标题】:how to create a infinite scrolling animation in action script3如何在动作脚本3中创建无限滚动动画
【发布时间】:2013-07-08 08:00:55
【问题描述】:

我正在创建一个鱼缸..所以我想做的是我的鱼应该是无限滚动的..我正在使用动作脚本 3..这是我使用的代码..但它不起作用..

var scrollSpeed:uint = 5;

//This adds two instances of the movie clip onto the stage.



//This positions the second movieclip next to the first one.
f1.x = 0;
f2.x = f1.width;

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

//This function moves both the images to left. If the first and second 
//images goes pass the left stage boundary then it gets moved to 
//the other side of the stage. 
function moveScroll(e:Event):void{
f1.x -= scrollSpeed;  
f2.x -= scrollSpeed;  

if(f1.x < +f1.width){
f1.x = f1.width;
}else if(f2.x < +f2.width){
f2.x = f2.width;
}
}

f1 和 f2 是我的鱼实例名称

【问题讨论】:

  • 我有点困惑,你是想在鱼离开一侧后将它们移到屏幕的另一侧吗?

标签: actionscript-3 flash flash-cs6


【解决方案1】:

你的问题列在底部。

if (f1.x < f1.width) {
    f1.x = stage.stageWidth - f1.width // f1.width;
} // Removed else

if (f2.x < f2.width) {
    f2.x = f1.width;
}

【讨论】:

    【解决方案2】:

    这假设您的图像/mc 足够大以显示屏幕,并且是重复的(具有相同的内容)

    function moveScroll(e:Event):void {
        //position fish 1
        f1.x -= scrollSpeed;
        //when fish 1 is out of bounds (off the screen on the left, set it back to 0
        if (f1.x < -f1.width) {
           f1.x = 0;
        }
        //always position fish2 next to fish 1
        f2.x = f1.x + f1.width;
    }
    

    如果它们没有相同的内容,另一种方法是将它们放在一个数组中并切换它们:

    //add fishes to array
    var images:Array = new Array();
    images.push(f1, f2);
    
    function moveScroll(e:Event):void {
        //position fish 1
        images[0].x -= scrollSpeed;
        //when first fish is out of bounds, remove it from the array (unshift) and add it at the end (push)
        if (images[0].x < -images[0].width) {
           images.push(images.unshift())
        }
        //always position fish2 next to fish 1
        images[1].x = images[0].x + images[0].width;
    }
    

    这些只是基本示例,但你明白了

    【讨论】:

      猜你喜欢
      • 2013-07-05
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2021-05-13
      相关资源
      最近更新 更多