Here's the second in my series of tutorials aimed at helping 2DIY users to use, and understand, actionscript within their creations.
This tutorial deals with creating 'monster' elements that will follow your horizontal position on screen, attempting to stop you passing.
Outline
In a 2DIY platform or maze game, you can make the challenge much harder by placing a monster element on a level that will attempt to stop you from passing by it. This is achieved by the monster following your movements with a slight delay.
Code Explanation
If you right click on a monster element, you will see the options for how to make the monster element move (the second option). Within this option there is an ‘advanced’ (ADV) setting where you can enter ActionScript code, and here we can set a rule to make the monster follow the horizontal position of the main character (but follow with a slight delay allowing time to pass by).
Tutorial
Create several platforms on screen for a character to jump on and rise up the screen. Place a character at the bottom of the screen, and a monster on the second to top platform. (Each platform layer will need a gap within it for the character to jump up through from the previous layer).
Right click on the monster and look for the animation settings option (the second option). Choose the advanced (ADV) option and click on the spanner icon* to open the Actionscript help editor. This editor allows you to select the code you need to use in blocks;
Using the editor you can select the following pieces of code;
_this (this tells the computer that it will be this element - the monster - to apply the changes to)
._x (this tells the computer the horizontal position along the screen to put the monster element)
+= (this sets the rule of what the value of x will be)
_root.player._x (this tells the computer to use the value of the horizontal position of your character)
- _this._x (this subtracts any difference between the horizontal position of your character and the monster)
/ 16 ( this value can be altered and affects how long the delay is between the position of the character and the monster. The smaller the number, the less the delay in movement)
*If you do not see the spanner icon, you are using an early copy of 2DIY and you will have to type the code in by hand. In this case enter the following;
this._x+= (_root.player._x - this._x) / 16;
Now press the play button, and move your character. You will notice that the monster follows where your character goes, but there is a slight delay.
What does this do?
You are telling the computer to constantly check the horizontal position of your character, and adjust the position of the monster accordingly to make it follow your characters horizontal position.
Task
Create a platform game with several layers. Each layer needs to have gaps within it to allow your character to leap up and onto the layer above.
Place your character at the bottom of the screen, and a monster on the second to top layer. You could also add additional monsters throughout other layers, and you will need to add an ‘apple’ element to the top most layer.
Notes
You could add a completely impassable monster within a game if you wished - maybe combined with the previous tutorial on teleporting - to confuse a player and make them think how solve the problem faced. To make an impassable monster, you would use the code
this._x=_root.player._x;
This tells the computer that whatever the horizontal position of your character (_root.player._x) is, make the monster’s horizontal position (this._x) the same.
You can find out more about this feature in this article


Recent Comments