More efficient: more code or constraints?
RossmanBrothersGames
Member Posts: 659
I was wondering if I could get your thoughts on what would be more efficient requiring less work for game salad. Having a simple constraint to do a process, or adding a line or two of code but removing the constraint.
I have two examples.
My game is a platformer were the character is always running, like rayman fiesta run. The character runs at two speeds depending on if you hold the sprint button. I have the speed constrained so that if bump into an object or a wall and slow down, once you clear the object you immedietly start running again. Would it be more efficient to add a line of code that says
If Linearvelocity.x is less than "maxspeed" then constrain the speed to "maxspeed" and otherwise if it is less change speed to "maxspeed" then just have my sprint button being released or pressed change the "maxspeed"
It would add another line of code but would it be better than constantly having a constrain
Similar example, there are many times i need to know if my character is moving up or down (animations, jumping on heads) is it better to just contain the y velocity to an attribute or add a rule saying
If linear velocity.y is > 0 change attribute to UP
otherwise change attribute to down
I have two examples.
My game is a platformer were the character is always running, like rayman fiesta run. The character runs at two speeds depending on if you hold the sprint button. I have the speed constrained so that if bump into an object or a wall and slow down, once you clear the object you immedietly start running again. Would it be more efficient to add a line of code that says
If Linearvelocity.x is less than "maxspeed" then constrain the speed to "maxspeed" and otherwise if it is less change speed to "maxspeed" then just have my sprint button being released or pressed change the "maxspeed"
It would add another line of code but would it be better than constantly having a constrain
Similar example, there are many times i need to know if my character is moving up or down (animations, jumping on heads) is it better to just contain the y velocity to an attribute or add a rule saying
If linear velocity.y is > 0 change attribute to UP
otherwise change attribute to down
Comments
But it is always better to find workarounds to replace as much constrain behaviors as yo could.
The running behavior of your main actor is a basic function of your game. If it works fine, I would not replace it.
But if you have lots of constrains in your enemies, obstacles, etc, then I would think of some other solutions for them. Instead of using lots of comparing rules to check the state of attributes, try to think about using a little bit of math in the expression editor.
Magic things can be done in there.
It is always nice and easy to create lots of rules in GS, but you can always combine several rules into one formula by using expressions and well thought logic.
www.rossmanbrosgames.com
A good place to look is google, searching this forum is also a good starting point, and they are listed inside the GS manual
http://cookbook.gamesalad.com/definitions
www.rossmanbrosgames.com