Stencyl For Noobs : Positioning and Movement

This is a “Stencyl For Noobs” guide! Take 5-10 minutes to go over this guide for a better understanding of the topic at hand!

Positioning and Movement

What we’re learning: How to move your actors around effectively; keeping multiple position/movement blocks from fighting each other.

Contents

How does Stencyl positon things?

How can I move my actors?
Method 1: Set actor coordinates
Method 2: Set actor speed
Method 3: Push the actor

Setting Position (Block 1) : Direct vs. Relative
Avoiding Movement Block Conflict

* * * * *

How does Stencyl position things?

In Stencyl, positioning is done by coordinates. Each pixel is an (x,y) point on your game screen when at a normal x1 resolution. The top-left pixel is (0,0), also know as the origin. If you move down, (y) gets larger. If you move right, (x) get larger. You can also move up and left from (0,0) for negative values, though actors at such positions may not be visible.

As an example, if your screen width is 400 pixels and your screen height is 200 pixels, then the bottom-right pixel of your screen will be (399, 199). This is because we started at (0,0) and not (1,1) at the top-left. We are saying that the bottom-right pixel is 399 pixels to the right of and 199 pixels below our origin. Does that make sense?

* * * * *

How can I move my actors?

In Stencyl, you have three different ways of moving your actor. They are:

  1. Set the actor at a specific (x,y) coordinate (Found under Actor >> Position)
  2. Set the actor’s speed in a specific direction (Found under Actor >> Movement)
  3. Push the actor with a force in a specific direction (Found under Actor >> Movement)

The BASIC blocks for each action are seen below.

Movement Blocks

You can also get related positional and movement data from the following blocks, found in the same areas mentioned above. Simply put, they return the x/y position of your actor (by default, the topleft or origin of your actor) and the x/y speed of your actor:

Movement Blocks 2

Method 1: Set actor coordinates

For block 1 above, simply fill in the x,y coordinates and it will try to move the specified actor to the position given. If you try to move it into an object or tile, Stencyl may catch that and adjust the actor’s position for you though.

Method 2: Set actor speed

Rather self-explanatory. For block 2, give your actor a speed and he will move in the specified direction.

Setting x-speed and y-speed follow the same schematic mentioned above. To move right (making your x value on the screen larger), give the actor a positive x-speed. To move up (making your y value on the screen smaller), give the actor a negative y-speed. And so forth.

Method 3: Push the actor

You can also choose to “push” the actor with a force.

You can choose to push “gently” or “sharply”. Which one should you use?

  • If you are pushing an actor consistently (accelerating a race car over time, for example), which is to say you are executing a push command over multiple frames, you will probably want to use “gently”.
  • If you are applying a sudden force (a pitcher just threw a baseball, for example), then you will probably want to use “sharply”.

The main difference is the time over which the force is applied. If you keep pushing from frame to frame, try using “gently”. If you push only once (a pitcher does not continue to push a baseball with his hand once it has left his hand), try using “sharply”. Experiment though, and see what works for you.

Again, the x and y field specify direction:

  • X : 1 = Push Right
  • X : -1 = Push Left
  • Y : 1 = Push Down
  • Y : -1 = Push Up

You can combine the two planes, of course, to do something like push up and right at the same time.

Then, simply specify the force’s power.

* * * * *

Setting Position (Block 1) : Direct vs. Relative

The following block is fine to use. It sets the actor’s position at the specified (x,y) point:

Movement Blocks 3

However, you can also use block 1 to move your actor in a specific direction, using the “X-of-Self” we discussed earlier and some math:

Movement Blocks 4

Do you see what happened? We looked at the x-position of the actor and moved him over “+3” (3 pixels to the right). We could have used “-3” too (3 pixels to the left). The same applies to the y-position. You may find this useful if you ever want to make fine adjustments to your actor’s positions, though I would caution you to avoid using this for any kind of regular movement (like an actor walking around), as it can produce choppy-looking results.

Avoiding Movement Block Conflict

Finally, you need to understand that these blocks can fight each other. It is not unusual to have two or three behaviors or events trying to move your actor through these blocks. However, certain blocks used together in certain ways can cause unpredictable results. It is important to limit what behaviors and events can do and at what times they can do it, so that behaviors and events are not fighting each other when moving the actor.

Below I have made a list of movement block combinations and have signified whether they typically act up when used together. B1, B2, and B3 refer to blocks 1, 2, and 3 respectively. B1 will also be denoted with direct or relative, as explained above. Also, understand the order of the blocks is switchable, as often it can be difficult in Stencyl to tell which block will go first.

  • B1 Direct + B1 Direct = Use Caution
  • B1 Direct + B1 Relative = Use Caution
  • B1 Direct + B2 = Use Caution
  • B1 Direct + B3 = Use Caution
  • B1 Relative + B1 Relative = OK
  • B1 Relative + B2 = OK
  • B1 Relative + B3 = OK
  • B2 + B2 = Unpredictable
  • B2 + B3 = Unpredictable
  • B3 + B3 = OK

This is probably the most complicated part of this guide. Let me break it down:

  1. Setting position does not directly influence the speed of your actor. However, it does put your actor at, yes, the exact spot you told it to (before checking for collisions and such). Just remember that it will pull your actor from whatever position he was in regardless of speed or whatever position he was in. You TECHNICALLY can use B1 Direct with the other blocks, just make sure you can order them correctly. For instance, though this may go without saying, if you want to move your actor to position A and then move him over 10 pixels, make sure you move him to position A first.
  2. On the other hand, setting position relatively is a little more forgiving, since you are doing it relative to the actor. In other words, if the actor’s position changes through a push before you execute a “move over 3 pixels” command, it will still move the actor over 3 pixels; it will just be relative to the actor’s new position. The reverse is true as well; if you moved over 3 pixels and then executed the push, the result would be the same. These two actions are capable of cooperating.
  3. Setting speeds often ignore whatever speeds the actor had beforehand. If you say set x-speed to 10, it will set it to 10 regardless of whether or not your actor’s x-speed was 0, 9, -4, or 1032 beforehand. They do NOT COMBINE. In general, avoid setting speeds in the same plane (x-axis/y-axis) twice in the same frame, as it may be difficult to determine which one will “win”.
  4. Forces influence speed. That means if you apply a force and THEN set speed, your actor’s speed (on that plane) will be exactly what the “set speed” put it at. Again, realize that they may NOT COMBINE correctly.
  5. On the other hand, forces DO COMBINE. You can apply as many forces to an actor in one frame as you like. It is possible for them to cancel out, but again, this can be natural (two bulls running into each other with the same force, for example) and whether or not that happens comes down to how you design your game to work.
Advertisements
Posted in Movement, Stencyl

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: