jeudi 18 février 2016

AS3 - Endless Vertically Scrolling Background

As my first AS3 project, I'm developing a simple space shooter/bullet hell game. I looked online for a way of producing an infinite background scrolling effect and found this working code.

    public function backgroundScroll (evt:Event):void
    {
        background1.y -= scrollspeed;
        background2.y -= scrollspeed;
        if (background1.y <= -background2.height)
        {               
            background1.y = background2.y + background2.height;
        }
        else if (background2.y <= -background2.height)
        {
            background2.y = background1.y + background1.height;
        }           
    }   

This causes the background to infinitely scroll upwards from the bottom of the screen without fail, but no matter what I try, I cannot cause it to instead infinitely scroll down from the top of the screen. Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire