View Full Version : Quick Overhead game question!
altoid_masta
05-23-2007, 10:45 PM
I've been working on an overhead RPG game. So far it's doing great. I just need help on one thing and I think I'll be able to figure everything else out.
I saw the simple overhead game tut on the tutorial collab, for the 16 millionth time already, and the code that Dr. Robot put up was incorrect. I need help constructing a code that has my character move in 8 directions, and so that it rotates to the following direction that it's going.
If I'm not making sense click here (http://www.newgrounds.com/portal/view/344206) and watch the tutorial.
What I don't want is for someone to give me the complete code, I want to do it on my own.
Thanks for the help in advance:D
EDIT:: I want the code to work so that the map moves, not the character. I kinda need to know how that works.
Make the entire map but your character a MovieClip. Give it the instance name of map.
Then on the frame do something like this.
map.onEnterFrame=function(){
//go up
if(Key.isDown(Key.UP)&&Key.isDown(Key.RIGHT)){
//up and right
_root.map._x-=_root.yourSpeed
_root.map._y-=_root.yourSpeed
//move the map in the opposite direction to give the effect of moving.
}
if(Key.isDown(Key.UP)&&Key.isDown(Key.LEFT)){
//up and left
_root.map._x+=_root.yourSpeed
_root.map._y-=_root.yourSpeed
//move the map in the opposite direction to give the effect of moving.
}
//check if your only holding the up button down to go straight up.
if(Key.isDown(Key.UP)&&!Key.isDown(Key.RIGHT)&&!Key.isDown(Key.LEFT)){
_root.map._y-=_root.yourSpeed
}
//do the same for the other directions.
}
truimagz
05-24-2007, 05:20 PM
ok crash course.
First thing you should know is dont use _root. or _level0. ever.
What I would reccomend is in your main .as create a var like this
var game = this
this way you can always reference the main timeline via "game" using _root or _level0 is not so good because things can change or move.
also for directions you should do something more like this
if(Key.isDown(Key.UP)){
game.map._y+=speed
}else if(Key.isDown(Key.DOWN){
game.map._y-=speed
}
if(Key.isDown(Key.LEFT)){
game.map._x+=speed
}else if(Key.isDown(Key.RIGHT){
game.map._x-=speed
}
this is pretty simple stuff so I hope you grasp it.
I would reccomend moving this into a class that handles all keypresses though.
altoid_masta
05-24-2007, 09:26 PM
Wait, so is this on an onClipEvent or onFunction thing?
Sorry, I'm still new at this.
truimagz
05-24-2007, 10:21 PM
DONT USE ON CLIP EVENTS EVER!!!
stop reading online tutorials and buy a book.
ry79418
05-25-2007, 05:29 AM
put it on the main time line like this
onEnterFrame=function(){
if(Key.isDown(Key.UP)){
game.map._y+=speed
}else if(Key.isDown(Key.DOWN){
game.map._y-=speed
}
if(Key.isDown(Key.LEFT)){
game.map._x+=speed
}else if(Key.isDown(Key.RIGHT){
game.map._x-=speed
}
}
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.