Here's the seventh in my series of tutorials aimed at helping 2DIY to use, and understand, actionscript within their creations.
This tutorial deals with increasing the speed of your main character.
Outline
In 2DIY platform activities, you can make your character move really slowly, and gradually increase the speed they move at using monster elements.
Code Explanation
Right click on a monster element and click on the collision options (the third option). Within this option there is an ‘advanced’ setting where you can enter ActionScript code, and here we can set a rule to increase the speed that a character moves at.
Tutorial
Create a platform activity. Add an monster element to the screen, right click on it, and look for the collision settings option (the third option). Choose the advanced option and type in the following code;
_root.dx=1;
_root.dx=1; this tells the activity to alter the speed of the main characters movement (by default ‘4’ is the normal value. Lower values are slower, and higher values are quicker)
Place the monster element in the same place as the main character element - this will ensure that when the activity starts the code is activated and the speed of the character is instantly slowed - and also make it transparent by colouring it in with the chequerboard pattern (you do not want to see the monster element on screen).
Place more monster elements at various points within the activity with the same code, but each time increase the value of the _root.dx= by 1 (so use 2, then 3, then 4). Above each transparent monster element you use, place a collectable apple element. This will give the effect of every time an apple is collected the characters speed will increase.
Now press the play button. Your character moves very slowly to begin with, but gradually speeds up as apples are collected, and the value of dx rises.
What does this do?
By increasing the value of dx you are increasing the speed that the main character moves at.
Task
Create a platform game. Add a character, and then add some apple elements at various places. Add some transparent monster elements below some of the apple elements using the code mentioned above.
Notes
You can use this in reverse - and begin with a fast moving character, but each time an apple element is collected the code is written so that the value of dx is reduced by 1 each time.


Recent Comments