Jump to content
  • Advertisement
Sign in to follow this  
toye

Flash Help, Please!

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey i was testing my game and the resolution is 300x400 and i made it on Flash MX 2004 but when Im playing the game and controlling my sprite you can make it so he just wonders off the screen. What do i do to stop him from just wodering off?

Share this post


Link to post
Share on other sites
Advertisement
First I will say I dont know how flash works...so this is just a general answer. I hope you can apply it.

You do a thing called "collision detection." When the players x position is greater than or equal to 300-playerxsize, you dont allow him to move. Same goes for when it is less than or equal to 0.

Here is some pseudo code to explain:


if(keydown == right){
//the guy should move right
if(xpos < 300 - xsize)
xpos++;
}
else if(keydown == left){
if(xpos > 0)
xpos--;
}
if(keydown == up){
if(ypos > 0)
ypos--;
}
if(keydown == down){
if(ypos < 400 - ysize)
ypos++;
}




There you go cheech. That should get you started. You want to make sure the position isn't outside the bounding area before you let him move.

Share this post


Link to post
Share on other sites
K well anyone that knows flash can tell me what to do? That last post helped me a bit but I still dont know what code to use, i'v been trying to google it for like the past couple hours lol

Share this post


Link to post
Share on other sites
COMON PEOPLE LOL ANYONEW ELSE KNOW WHAT KIND OF CODE I SHOULD USE OR HOW TO FIX THIS PROBLEM?

Share this post


Link to post
Share on other sites
ok here ya go, let me know if this isnt what your looking for


if (Key.IsDOWN(key.RIGHT) && player._x < 300)
{
player._x = player._x + 2;
}

if (Key.IsDOWN(key.LEFT) && player._x > 1)
{
player._x = player._x - 2;
}


then same thing for the _y to catch top and bottom, of course im assuming player is the varible name for whatever your character name is

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!