Wednesday, October 9, 2013

Building custom controls in Stencyl - Part 2

Next is adding custom controlls to you game. Press the settings button. Tnen press Controls tab.

You can now see controls: up, down, left, right, x, z and enter. Remove x, z and enter controls as we will not use them. Add 4 more controls W, A, S and D. Then add control Pause and set it to button P.
Check the images below



Select Actors Behaviors item in the dashboard. Select "8 Way Movement" behavior, right click and press duplicate behavior. Double click on the copied behavior and press the properties tab. Rename it ArrowsWASDController. The trick is to add the missing keyboard buttons in the code so that when changes applied you can controll the character with both WASD and arrow key sets.

Here is a screenshot of the changes I have made to our copied behavior:

Copied "8 Way Movement" behavior

This is on the updating event. See only the top part. I added simple "or" condition and added corresponding button presses. The next pic is the updating event on the original "8 Way movement" behavior just to show you the differences:

Original "8 Way Movement" behavior   
Once you are finsihed editing of ArrowsWASDController behavior don't forget to press the "Attach to Actor" button. Attach it to SpaceRanger. You may think, we have added another behavior that does roughly the same thing as the first one. Well go to behaviors tab of "Space Ranger" actor and deactivate original "8 Way movement" behavior. You may also remove it if you like.

Note: As a practice you can search the behaviors and find "Cannot exit screen" behavior in Motions section. This will prevent the main character to fall off the screen and disapear.

Ok thats it for this part. Press ctrl-enter to test the game. Don't forget File->Save Game to save the progress.

No comments:

Post a Comment