2DIY ActionScript Tutorials T1 - Making a Character Jump to a New Location Outline In a 2DIY platform or maze game, you can create an interesting effect when your character collides with a monster. Instead of the character losing a life or losing points, you can make the character ‘jump’ to a new location. In this task you are going to make a character jump to a different part of the screen. Code Explanation If you right click on a monster element, you will see the options for what to do during the ‘collision’ between the monster and character (the third 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 character move to a new location on the screen by setting the x (horizontal) and y (vertical) positions. Tutorial Place a character and a monster on the screen. Right click on the monster and look for the collision settings option (the third 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; _root.player (this tells the computer what is going to be affected) ._x or ._y (this tells the computer the position along / down the screen for the action) = (this sets the rule of what the value of x or y will be) More information, examples and help can be found at http://www.2diyarchive.co.uk 2DIY is ©2Simple Software http://www.2simple.com/2diy
The final block lets you set the position value of x or y using pixels (see the notes area below for an explanation of the values of both x and y)
*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; _root.player._x=20; _root.player._y=440; Now press the play button, move the character onto the monster element and see what happens. What does this code do? You are telling the computer that when the character (_root.player) collides with the monster element, the x and y positions of the character are to be changed. This causes the character to jump to that new location instantly. It gives the effect of a ‘teleport’. More information, examples and help can be found at http://www.2diyarchive.co.uk 2DIY is ©2Simple Software http://www.2simple.com/2diy
Task Create a platform game with two separate areas on the screen. Place your character in one area, and an ‘apple’ element in the other area. The areas can be separated by using wall elements to block the characters route to an ‘apple’ element. You will need to add a monster element within the first area, and change the collision effect so that your character can use it to ‘teleport’ and reach the other side of the screen. Notes On the 2DIY screen, the x value is 0 on the left of the screen, and 640 on the right. The y value is 0 at the top of the screen and 480 at the bottom of the screen.
You can find out more about this feature on the 2DIY archive: www.2diyarchive.co.uk/2009/03/teleport-a-character-to-anotherlocation.html
More information, examples and help can be found at http://www.2diyarchive.co.uk 2DIY is ©2Simple Software http://www.2simple.com/2diy