Apr 11, 2007

Creating walls

Example : Walls

Ok, here we are going to creat walls, so you animation can't go through, lets get started by opening the movement with arrows file we created, ok now creat a line , hit F8 and convert it into a symbol, give it the name you want, and for instance name lets put an "l" that means it is the left wall, and now we give the animation you move with the arrows keys an instance name of "man".... let's start coding!
onEnterFrame = function (){
\\this detetcts if "man" hits the wall
_root.man._x += 6;

\\Here its says that if the hitTest is true, or actually touching the wall the x coordenate of the \\position of your "man" sill increase by 6, 1 pixel higher than the speed, so it wont go trhough.

Now you have figured out how to make the left wall, how about we start with the top one...Creat another wall that is horizontal and place it on the top of the screen. Give it an instance name of "t"..... Lets start.

_root.man._y += 6;
\\Here we are doing what we did earlier with the left wall, only the coordenate changes to _y
\\this says that if hitTest is true the _y value of the position of the "man" should increase by 6
\\ like before the number should always be greater than the speed, so it wont go through...

This code should go tight after the left wall code.... We got 2 walls working now I hope you can figure the other 2 out.... just by changing by positive to negative, and remember to close the onEnterFrame with "}".

Hope you find it usefull...


No comments:


Kevin Stubbs, Ivan Alvarez Malo