PDA

View Full Version : [AS3] Platform game troubles


DaPalooka
12-14-2010, 11:59 PM
im using actionscript 3.0 and Adobe flash professional CS5



Im making a platformer, everything runs fine but I cant get the stickman(instance name: hero) to follow my mouse left. He only follows the mouse right.


Any fixes??

//heres the code

import flash.events.Event;

var vy:Number=0
var jumped:Boolean=false;
var gv:Number=1;

addEventListener(Event.ENTER_FRAME,ctrl_hero);
stage.addEventListener(MouseEvent.CLICK, jump);

function ctrl_hero(e:Event){
if(hero.x-20<mouseX){
hero.x+=5;
}
if(hero.x+20<mouseX){
hero.x-=5;
}
vy+=gv;

if(! level.hitTestPoint(hero.x,hero.y,true)) {
hero.y+=vy;
}
if (vy>10){
vy=10;
}
for (var i:int = 0; i<10; i++) {
if (level.hitTestPoint(hero.x,hero.y,true)) {
hero.y--;
vy=0;
jumped=false;
}
}
}
function jump(e:Event){
if(!jumped){
hero.y-=5;
vy=-20;
jumped=true;
}
}

plasticsturgeon
12-15-2010, 12:15 AM
function ctrl_hero(e:Event){
if(hero.x-20<mouseX){ // Problem LINE
hero.x+=5;
}
if(hero.x+20<mouseX){ //Problem LINE
hero.x-=5;
}


Try making it > instead of <
if(hero.x-20>mouseX){

DaPalooka
12-15-2010, 12:53 AM
its fixed man, thanks!



Hey, if you can help me out even further, how do I change the jump button to UP ARROW, and instead of him following my mouse, make him move with the LEFT and RIGHT arrow keys?