Android Scrolling Background
hi there guys!
i making side scrolling runner game in air android actionscript3.
i have 2 working buttons: 1 jump button , 1 run button - working perfectly.
my character placed on center left of stage user has more of preview before encounter obstacle.
now problem how make background scroll left when character runs right, character can still jump when press jump button. can’t figure out guys please help! t_t
the 'walking' , 'still' animations character.
this codes jump , 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;
}
if trying have 2 buttons can held down together, run , @ same time user can click jump must use touch events , not mouse events due fact 1 mouse event can fire off @ 1 time on stage because events designed mouse cannot have 2 clicks happening @ same time.
so switch mouse events touch events or if designed desktop map jump events button right click or space bar.
More discussions in AIR Development
adobe
Comments
Post a Comment