To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-13-2004, 05:35 PM   #1
veckholm
Member
 
Join Date: Feb 2002
Location: Chicago, Atlanta
Posts: 57
Maze hitTest

Im making a maze that ball travels through. I am succesful on one wall. But when I come down to the other side it brings it up. How do make the side a hitTest? or can give me advice if theres better solutions. Thanks....
I have attached it to the ball named circle. I have include the file


//the hitTest
if (hitTest(_level0.wall)==true) {
_y = _y-10;
this below is the full code
onClipEvent (enterFrame) {
if (Key.isDown(37)) {
_x=_x-10;
}
if (Key.isDown(38)) {
_y=_y-10;
}
if (Key.isDown(39)) {
_x=_x+10;
}
if (Key.isDown(40)) {
_y=_y+10;
}
//the hit test
if (hitTest(_level0.wall)==true) {
_y = _y-10;


}

}
Attached Files
File Type: fla maze.fla (47.5 KB, 197 views)
veckholm is offline   Reply With Quote
Old 10-13-2004, 06:00 PM   #2
jbum
Senior Member
 
jbum's Avatar
 
Join Date: Feb 2004
Location: Los Angeles
Posts: 2,920
I would do a coordinate based hit test which checks the direction you are trying to travel in.

Your current makes an adjustment to the position, and then does an 'undo' on that adjustment if there is a hit.

I would check to see if there is a hit on the target coordinates before making the actual adjustment, like so:

code:

onClipEvent (enterFrame) {

var xd = 0; // direction of movement
var yd = 0;
if (Key.isDown(37)) {
xd = -10;
}
if (Key.isDown(38)) {
yd = -10;
}
if (Key.isDown(39)) {
xd = 10;
}
if (Key.isDown(40)) {
yd = 10;
}
// check if there is a collision with the target coords
if (!_level0.wall.hitTest(_x+xd,_y+yd))
{
// if not, make the adjustment
_x += xd;
_y += yd;
}
}



Also, there's another way to do it, the method I used in these mazes:

http://krazydad.com/fungames.php

In these mazes, I don't use hitTest at all, instead I keep track of where the valid paths exiting each cell are and only allow movement along the valid paths, tweening from the center of one cell to the next.

So rather than using hitTest, I am checking a data structure to see if a bit is set that corresponds to the desired direction of movement.

- Jim
__________________
jbum is offline   Reply With Quote
Old 10-13-2004, 06:09 PM   #3
veckholm
Member
 
Join Date: Feb 2002
Location: Chicago, Atlanta
Posts: 57
Thanks you

Thanks so very much for the help.
veckholm is offline   Reply With Quote
Old 03-17-2005, 09:56 AM   #4
webguy0000
Junior Member
 
Join Date: Mar 2005
Location: minds playin tricks on me
Posts: 18
http://www.actionscript.org/tutorial...es/index.shtml

I remembered seeing this, thought you might be interested.

webg
__________________
minds playin tricks on me
webguy0000 is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:30 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.