Be a Supporter!

Boundaries AS2

  • 677 Views
  • 7 Replies
New Topic Respond to this Topic
YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Boundaries AS2 2011-11-20 00:49:00 Reply

so yea.. i've got this game i've been working on. It's coming along nicely... but there's one thing i'm having problems with. I have a free roaming character where you control him with the arrow keys. I basically want to figure out how you can set boundaries for him so that he doesn't just walk right above or through things. I have depth perception set up so that he can walk around things.. but i want to be able to set boundaries for where the red line is. Look at this quick sketch i set up for my game. I want to make sure he stays below that red line. What kind of AS2 concept would be necessary for such a thing?????

Boundaries AS2


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Boundaries AS2 2011-11-20 02:34:15 Reply

The concept isn't anymore as complex as to when depth perception isn't involved. He's still moving along the Y axis, I assume the way you're making it look like he's moving away is by scaling him smaller.

Just do a shape flag hitTest against a boundaries movieclip, exactly the way you would with a top down game.

onEnterFrame = function(){
     while(boundariesMC.hitTest(player._x+5, player._y, true)){
          player._x--;
     }
     while(boundariesMC.hitTest(player._x-5, player._y, true)){
          player._x++;
     }
     while(boundariesMC.hitTest(player._x, player._y-5, true)){
          player._y++;
     }
     while(boundariesMC.hitTest(player._x, player._y, true)){
          player._y--;
     }
}

Assuming the registration point of the player movieclip is at his feet, that shouldn't look too bad at all.

YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Response to Boundaries AS2 2011-11-20 12:17:53 Reply

okay cool. it works! BUT.. how do i make him stop scaling when he reaches the line?????


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!

YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Response to Boundaries AS2 2011-11-24 11:59:34 Reply

At 11/20/11 12:17 PM, YoinK wrote: okay cool. it works! BUT.. how do i make him stop scaling when he reaches the line?????

i figured this out on my own actually. I set up an equation that adjusts the scaling based upon where the player is at on the Y-axis. :D


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Boundaries AS2 2011-11-24 12:12:04 Reply

Level 59, respect.


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

Sandremss128
Sandremss128
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Supporter
Level 11
Programmer
Response to Boundaries AS2 2011-11-24 12:25:24 Reply

You are the only one on NG who has lvl 59 I am right?

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Boundaries AS2 2011-11-25 00:39:24 Reply

At 11/24/11 11:59 AM, YoinK wrote:
At 11/20/11 12:17 PM, YoinK wrote: okay cool. it works! BUT.. how do i make him stop scaling when he reaches the line?????
i figured this out on my own actually. I set up an equation that adjusts the scaling based upon where the player is at on the Y-axis. :D

That's the best way to do it, rather than changing it on key press.

YoinK
YoinK
  • Member since: Jan. 5, 2001
  • Offline.
Forum Stats
Member
Level 60
Game Developer
Response to Boundaries AS2 2011-11-26 17:37:05 Reply

At 11/25/11 12:39 AM, Sam wrote:
At 11/24/11 11:59 AM, YoinK wrote:
At 11/20/11 12:17 PM, YoinK wrote: okay cool. it works! BUT.. how do i make him stop scaling when he reaches the line?????
i figured this out on my own actually. I set up an equation that adjusts the scaling based upon where the player is at on the Y-axis. :D
That's the best way to do it, rather than changing it on key press.

yea! Another thing is... i have the character set up as an onClipEvent rather than an onEnterFrame because it's a fully customizable character where you can change his appearance. when i have it set as onEnterFrame function it has a delay with the look of the character....


Kanye West Did What??????
They should make a black guy the manager, they know how to run shit!
2 Girls 1 Cup .... THE SONG!!!!