The web site for Flash ActionScript 3.0 game developers

 
         
   

Issues with scrolling

Hello, I'm looking for some assistance with some side scrolling issues I'm having with my code. This is my first time really coding so any and all help/advice would be a big help! In total I have 3 timelines running, one for pure Action script, one for my movie clips, and a final for my background(this line I have not started to work with, and am not currently concerned about).

So here is my code(its a bit messy, please forgive me):

~~~~~~~
hero.gotoAndStop('still');

var friction:Number=.9;
var speed:Number=0;
var dy:Number=0;
var gravity:Number=4;
var canjump:Boolean = false;
var Key:KeyObject = new KeyObject(stage);

stage.addEventListener(Event.ENTER_FRAME,onenter);

scrollStage();

function scrollStage():void
{
ground.x += (stage.stageWidth * .5) + hero.x;
hero.x =(stage.stageWidth * 0.5);
}

function onenter(e:Event):void{

dy+=gravity;

if(hero.y>300){
canjump=true;
}
if(Key.isDown(Key.UP) && canjump){
dy=-25;
canjump=false;
}
hero.y+=dy;

if (Key.isDown(Key.RIGHT)){
speed-=6
hero.x+=12;
hero.scaleX=1;
hero.gotoAndStop('walking');
}else if (Key.isDown(Key.LEFT)){
speed+=6
hero.x+=-12;
hero.scaleX=-1;
hero.gotoAndStop('walking');
}else {
hero.gotoAndStop('still');
}
if (speed>20){
speed=20;
}
if (speed<(-20)) {
speed=-20;
}
speed=speed*friction;
hero.x-=speed;

if (Math.abs(speed)<0.0009);{

if (! ground.hitTestPoint(hero.x,hero.y,true)) {
hero.y+=dy;
canjump=false;
}
if (dy>10) {
dy=10;
}
for (var i:int = 0; i<10; i++) {
if (ground.hitTestPoint(hero.x,hero.y,true)) {
hero.y--;
dy=0;
canjump=true;
}
}
function scrollStage():void
{
ground.x += (stage.stageWidth * 1) - hero.x;
hero.x = stage.stageWidth * 1;
}

}
}
~~~~~~~~~~~~~~~~

Again any advice on my situation would be greatly appreciated.

Thanks
-Windwarp



Copyright Gary Rosenzweig