Skip to main content
Known Participant
January 15, 2013
Question

Android Scrolling Background

  • January 15, 2013
  • 4 replies
  • 867 views

Hi there guys!

I am making a side scrolling runner game in AIR FOR ANDROID ACTIONSCRIPT3.

I have two working buttons: One for the Jump button and One for the Run button - It is already working perfectly.

My character is placed on the center left of the stage so the user has more of a preview before they encounter an obstacle.

Now my problem is how to make the background scroll to the left when the character runs to the right, also the Character can still jump when i press the jump button. I can’t figure it out guys please help! T_T

The 'walking' and 'still' are animations for the character.

This is are my codes for the jump and run button:

var dy:Number = 0;

var gravity:Number = 1;

var canjump:Boolean = false;

hero.gotoAndStop('still');

hero.speed = 0;

hero.upval = 0;

right_btn.addEventListener(MouseEvent.MOUSE_DOWN, doRight);

jump_btn.addEventListener(MouseEvent.MOUSE_DOWN, doUp);

stage.addEventListener(MouseEvent.MOUSE_UP, doStill);

stage.addEventListener(Event.ENTER_FRAME,onenter);

function doRight(e:Event):void

{

          hero.speed = 5;

          hero.scaleX = -1;

          hero.gotoAndStop('walking');

}

function doUp(e:Event):void

{

          hero.upval = -20;

}

function doStill(e:Event):void

{

          hero.upval = 0;

          hero.speed = 0;

          hero.gotoAndStop('still');

}

function onenter(e:Event):void

{

          hero.x +=  hero.speed;

          dy +=  gravity;

          if (hero.y > 441.95)

          {

                    dy = 0;

                    canjump = true;

          }

          if (canjump)

          {

                    dy = hero.upval;

                    canjump = false;

          }

          hero.y +=  dy;

}

This topic has been closed for replies.

4 replies

Mark.fromOP
Inspiring
January 16, 2013

If you are trying to have two buttons that can be held down together, like run and then at the same time the user can click jump then you must use Touch events and not Mouse events this is due to the fact that only one Mouse event can fire off at any one time on the stage because those events were designed for the mouse where you cannot have 2 clicks happening at the same time.

So switch your mouse events to touch events or if this is designed for the desktop map your jump events to a button like right click or space bar.

Known Participant
January 16, 2013

Oh men! When i tried to use Touch Events the buttons doesn't work when I test movie it at adobe flash.

Mark.fromOP
Inspiring
January 16, 2013

What version of flash are you using? In flash CS6 when you preview your app you are able to test touch events but you must turn that on in the panel that pops up to the left.

Otherwise you have to test on the device.