Skip to main content
Known Participant
January 13, 2013
Question

Character in the Center of Screen

  • January 13, 2013
  • 2 replies
  • 555 views

Hi guys please help again :angel::confused:

I am making a android platform game in flash actionscript 3. It is a side scrolling runner game.

So what I want is to make my character be on the center of the screen all the time. When it runs the character will always be at the center of the stage/screen. When I press the run button my character runs to the right then the background scrolls to the left.

Please help guys, I am still new in this actionscript 3 programming. I can't find any tutorials in the net on actionscript 3 T_T.

This topic has been closed for replies.

2 replies

Mark.fromOP
Inspiring
January 13, 2013

Well what you need to do is have you characters centered. Also consider putting your character more to the left if the character runs to the right so the user has more of a preview before they encounter an obstacle.

Then when the user hits a preset button or portion of the screen instead of moving the character you scroll the background to the left, so the character actually stays put and the background moves but it looks like the character is moving. I have no experience with this but as you move through the background you can load objects and obstacles dynamically from the library via addChild and remove them when they are off screen or destroyed, this is the complex part. You will also need some sort of collision detection and perhaps some physics if the character is not running on even ground or if objects need the ability to bounce off surfaces and deal with gravity.

Known Participant
January 14, 2013

OMG so giving the character some actionscript motion is wrong??

Please help me sir i am very new to actionscript programming sir, I can't figure it out

Do you mind to see my codes. I have two buttons for my character, Jump button and Move button that moves only ti the right..

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;

}