Stopping actors going off screen - How to

quantumsheepquantumsheep Member Posts: 8,188
edited November -1 in Working with GS (Mac)
Hey all, hope you're well.

I've seen some discussion here (e.g. http://gamesalad.com/forums/topic.php?id=140 ) about keeping an actor on-screen.

A lot of suggestions have included using invisible walls, but I always thought that was a bit of a hack, and adds extra actors you might not need.

My solution is this.

The iphone screen size is X: 480 Y:320

On the actor you want to stay within these screen limits, use these rules.

Constrain the actors X and Y positions to the edge of the screen by using rules to check if the actor is beyond this and then moving the actor back on.

Hopefully these screenshots will be clearer:

http://quantumsheep.googlepages.com/Screenconstraints1.jpg

Here you can see that if the X position of the actor is less than 10, then we constrain the actor's self position to 10.

Additionally, if his position is greater than 470 then it is constrained to 470.

We also do the same with the Y position of the actor like this:

http://quantumsheep.googlepages.com/screenconstraints2.jpg

You can experiment with how close you want the actor to get to the edge. Also, you can remove the constraint and add a move attribute to make them move *away* from the edge (if it's an NPC for example).

This can also be used to destroy an actor once they've gone off the screen with a little tweaking.

Hope that's clear, and that it helps.

Cheers,

QS

Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io

Comments

  • JGary321JGary321 Member Posts: 1,246
    Nice, I'll keep this one in mind =)

    I would think this is better performance-wise than creating an additional actor.

    -JGary
  • butterbeanbutterbean Member Posts: 4,315
    Quantum

    What if you have an actor on the bottom of the screen, on the X axis, and you only want that actor to stay on the ground, and not move up or down, or float away, how would you do that?

    If you can show screens like you did above too, that would be great!

    I'm assuming you would use the constrain attribute, but I just wanted to clarify

    The actor only moves left and right on the X axis, as if he's walking side to side on the ground

    Thanks Quantum!

    I haven't been in the forums much in the past week, so if this has been mentioned, please pardon my amnesia, and refer me to that place :)
  • JGary321JGary321 Member Posts: 1,246
    I would think you would just constrain the Y axis to whatever you wanted it to stay at. That way it could not go up & down.

    -JGary
  • butterbeanbutterbean Member Posts: 4,315
    So I basically, under the actor prototype, created a rule, and said, if an attribute changes, self position y is greater than 1, AND self position y is less than 0, then constrain attribute, self position y to 0

    I haven't had problems with my actor floating yet, but I thought I better put this rule in place to prevent this possibility

    Do you have another suggestion, or does this sound like the right rule to create?
  • JGary321JGary321 Member Posts: 1,246
    I don't THINK you need a rule. You should be able to just drag over the constrain attribute & set it to whatever you want. That should work. The less rules you have the better. (For optimization) Good Luck!

    -JGary
Sign In or Register to comment.