Wednesday, September 24, 2014

STENCYL BEHAVIORS - "Back and Forth Horizontally"

In Stencyl, we have a package ready behaviors that allow us to quickly create a basic game. However, and this behavior can be modified and improved as our needs. I'll show you how to do this in a Back and Forth Horizontally.

First, let's get to the simple game we created in the previous tutorial about homming missile.


Here a link to this tutorial: http://retros-games-ilike.blogspot.com/2014/09/stencyl-homming-missile-system.html

So we choose our actor to whom you want to assign this behavior.


We then assign them to remain "back and forth horizontally" included in the category of motion.


As you can see, the behavior can set parameters such as speed, initial direction, distance left, right distance and change of direction in the event of a collision.


Let's change our behavior, so that it is more flexible. I suggest you change the variable "speed" so that it is a random number from a specified range.



Click on the "Edit Behavior" and you see;


Important - not to overwrite itself in our behavior. Click on properties and create your own under a different name. For example: "Back and Forth Horizontally 2". Then, make sure that it is the behavior part of our "bulletcreator".



Let's say that each time the distance covered to the left or to the right, the speed will be changed to the new value in the range of 10 - 50 For this we need to put individual pieces of code, as shown in the figure.



As you can see, the movement of our "bulletcreator" is already a bit more chaotic.





Change the value of the random velocity is, however, uncomfortable, every time we would go into editing behavior.
Therefore, we create two variables (attributes). Let's call them "minimumSpeed​​" and "maximumSpeed​​"


It is important that our created attributes were not hidden. Then we can change them from the main without going into edit mode code.


Ready behavior is often the ideal primer for further modification. It is already a matter of our imagination. We could, for example, change the "Distance Left" and "Right Distance" with the passage of time. We could also use an increase in "speed" as time goes on. As the picture below.

Worth experimenting, the results can often surprise us and modified behavior will be useful in the future.





No comments:

Post a Comment