Flash Tutorial – Arranging a scene (Part Two) using hitTest
05 Feb 2008 7 Comments
In the first tutorial (Arranging a scene using depths & scale) I created a scene that gives the impression that a character can move around scenery using the _y property. This tutorial explains how to stop the character moving through the scenery using hitTest.
First, create the file from the first tutorial.
In the Scene
Create a new movie clip and add a rectangular shape in it. Place this movie clip in each of your character and scenery movie clips, re-sizing it to the width of the item and the height to represent the “depth” – see diagram. Name each of the rectangular movie clips “testarea” and set the alpha to 0%.
Initial Variables
Add this below the intial variables in the Actions frame.
moveAllowed = true;
Additional Code
In the mouseListener function, replace the code
_root.Character._x = _root._xmouse;
_root.Character._y = _root._ymouse;
with this code
if (_root.moveAllowed) {
_root.Character._y = _root._ymouse;
_root.Character._x = _root._xmouse;
} else {
_root.Character._x = _root._xmouse;
}
for (i=0; i<DepthArray.length; i++) {
if (_root.DepthArray[i].mcname != "Character") {
if (_root.Character.testarea.hitTest(_root[DepthArray[i].mcname].testarea)) {
_root.moveAllowed = false;
break;
} else {
_root.moveAllowed = true;
}
}
}
And so…
7 Comments (+add yours?)
Leave a Reply
RSS
Sep 06, 2008 @ 09:39:26
found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later ..
Oct 22, 2008 @ 22:43:23
Howdy Expert, I am glad I pressed harder enough until I found movie scenes, because this post on Tutorial – Arranging a scene (Part Two) using hitTest at elaine is bored now was extremely helpful. Just last Wednesday I was pondering on this quite a bit.
Oct 30, 2008 @ 01:43:34
Hey!, what made you want to write on Tutorial – Arranging a scene (Part Two) using hitTest at elaine is bored now? I was wondering, because I have been thinking about this since last Wednesday.
Nov 11, 2008 @ 18:34:14
This might be a topic that we would like to extend on our forum about it, would you like to participate?
Jan 28, 2009 @ 04:58:30
Wow! Thank you very much!
I always wanted to write in my blog something like that. Can I take part of your post to my site?
Of course, I will add backlink?
Sincerely, Timur I.
Feb 06, 2009 @ 03:12:49
Hi. Your site displays incorrectly in Firefox, but content excellent! Thanks for your wise words:)
Mar 14, 2009 @ 17:31:12
If Timur it is possible, also I will take, I will place here best-disk.ru