Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-14-2010, 11:59 PM   #1
DaPalooka
Registered User
 
Join Date: Dec 2010
Posts: 15
Default [AS3] Platform game troubles

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;
}
}

Last edited by DaPalooka; 12-15-2010 at 12:02 AM.
DaPalooka is offline   Reply With Quote
Old 12-15-2010, 12:15 AM   #2
plasticsturgeon
Actionscript Blogger
 
Join Date: Jun 2010
Location: Hollywood, CA
Posts: 106
Default

ActionScript Code:
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 <
ActionScript Code:
if(hero.x-20>mouseX){
plasticsturgeon is offline   Reply With Quote
Old 12-15-2010, 12:53 AM   #3
DaPalooka
Registered User
 
Join Date: Dec 2010
Posts: 15
Default

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?
DaPalooka is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:29 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.