00:00
00:00
Newgrounds Background Image Theme

Chan99 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Boundaries AS2

1,118 Views | 7 Replies
New Topic Respond to this Topic

Boundaries AS2 2011-11-20 00:49:00


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

Response to Boundaries AS2 2011-11-20 02:34:15


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.

Response to Boundaries AS2 2011-11-20 12:17:53


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

Response to Boundaries AS2 2011-11-24 11:59:34


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

Response to Boundaries AS2 2011-11-24 12:12:04


Level 59, respect.


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

Response to Boundaries AS2 2011-11-24 12:25:24


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

Response to Boundaries AS2 2011-11-25 00:39:24


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.

Response to Boundaries AS2 2011-11-26 17:37:05


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....