LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
  #1  
Old 05-13-2002, 05:58 AM
Dndb's Avatar
Dndb Dndb is offline
Registered User
 
Join Date: Mar 2002
Location: Hong Kong
Posts: 15
Rep Power: 0
Dndb is on a distinguished road
Question How can detect the moon shape and square are collision ?

How can detect the moon shape and square are collision ?
  #2  
Old 05-20-2002, 06:13 AM
Dndb's Avatar
Dndb Dndb is offline
Registered User
 
Join Date: Mar 2002
Location: Hong Kong
Posts: 15
Rep Power: 0
Dndb is on a distinguished road
Cyborg

nobody reply ...
  #3  
Old 05-20-2002, 08:33 AM
swoop's Avatar
swoop swoop is offline

swoopy HyperModerator
 
Join Date: Jun 2001
Location: England
Posts: 1,562
Rep Power: 14
swoop is on a distinguished road
Hi Dndb, welcome to flashmove,

You need to use the 'MovieClip.hitTest()' method.

swoop
  #4  
Old 05-20-2002, 01:40 PM
Dndb's Avatar
Dndb Dndb is offline
Registered User
 
Join Date: Mar 2002
Location: Hong Kong
Posts: 15
Rep Power: 0
Dndb is on a distinguished road
U see .
it doesn't work good ~
when the cicrle does not touch the moon yet , it become alpha ~
[broken]http://primarycolour.uhome.net/show.swf[/broken]
How can solve it
This fla
  #5  
Old 05-21-2002, 10:45 AM
swoop's Avatar
swoop swoop is offline

swoopy HyperModerator
 
Join Date: Jun 2001
Location: England
Posts: 1,562
Rep Power: 14
swoop is on a distinguished road
The problem is that there is two different versions of the 'movieClip.hitTest()' method. The one you are using in your example is the most common one. However it suffers from the problem that it checks the bounding boxes of the two specified movieClips, rather than the contents of the movieClip. So rather than checking your moon shape it is checking against the rectangle shape round the outside.

The way around this is to use Flash's shape-testing method of hitTest collision detection. Now unfortunately it is not as simple as simple as specifying the two movieClips. The syntax is:
Actionscript:
_root.moon.hitTest(this._x, this._y, true);

This tests the exact shape of the moon against the centre point of the circle, this is better but not ideal, as it means that the circle still has to overlap by quite alot before it registers. This code is better for keeping something inside an odd shape rather than outside.

The best solution for your problem is to do multiple checks against the centre point +-8 pixels. Check out the zip file.

swoop
Attached Files
File Type: zip show_new.zip (5.4 KB, 86 views)
  #6  
Old 05-21-2002, 01:27 PM
Dndb's Avatar
Dndb Dndb is offline
Registered User
 
Join Date: Mar 2002
Location: Hong Kong
Posts: 15
Rep Power: 0
Dndb is on a distinguished road
Machine

Thx a lot !
I have learn a good idea from you "swoop" !
  #7  
Old 12-02-2002, 03:36 PM
g_M_e g_M_e is offline
Registered User
 
Join Date: Dec 2002
Location: Hell, MT
Posts: 5
Rep Power: 0
g_M_e is on a distinguished road
Hi!

I could really use some help with hitTest if either of you can or care to help. I'm having problems with true collision detection. I've used the code that swoop provided, but my code is missing something. Please check out my post @ http://www.flashmove.com/board/showt...threadid=8734. Any help would be greatly appreciated.

Thanks in Advance!
  #8  
Old 12-02-2002, 03:42 PM
prisma prisma is offline

Super Moderator
 
Join Date: May 2001
Location: Munich, Germany
Posts: 1,668
Rep Power: 14
prisma is on a distinguished road
Regarding 'true' collision detection I made a post with an example not long ago: http://www.flashmove.com/board/showt...?threadid=8503

But I dont see how that whould help you with your problem.
__________________
... take me to your coder.
  #9  
Old 01-03-2003, 06:09 PM
FXInc FXInc is offline
Registered User
 
Join Date: Oct 2000
Posts: 21
Rep Power: 0
FXInc is on a distinguished road
I couldn't find any easy solutions. Here's something that works, but more work than I would like to do. If you find a solution(easier) please let me know.
Attached Files
File Type: zip xshow.zip (2.9 KB, 24 views)
  #10  
Old 01-03-2003, 08:20 PM
prisma prisma is offline

Super Moderator
 
Join Date: May 2001
Location: Munich, Germany
Posts: 1,668
Rep Power: 14
prisma is on a distinguished road
I found a similar way, but maybe a bit easyer to create:
http://www.dalord.yi.org/prisma/flas...collision2.swf
http://www.dalord.yi.org/prisma/flas...collision2.fla
(I hope the server works. It often doesn't)

How did I create the hitme shape?
Simple: Modify > Shape > Expand Fill

Only works with circle collision though. (Expand the fill by the diameter of the circle)
__________________
... take me to your coder.
  #11  
Old 01-03-2003, 08:28 PM
g_M_e g_M_e is offline
Registered User
 
Join Date: Dec 2002
Location: Hell, MT
Posts: 5
Rep Power: 0
g_M_e is on a distinguished road
I've finally figured this out about 2 weeks ago, i forgot I posted on this thread. Prisma provided a good example of a basic hitTest, but to get even better collision detection you must test the bounding box and the center. I was at flash kit, searching and posting and I found a piece of code by the master Ed Mac.

I include the following AS to my hero MCs the user can control. The function is a variation of Ed Mac's Code, click here to view it at flashkit.com. Ed Mac's original code test the corners of the bounding box, my code is the heuristics where we test agains the center aswell. This extra step is required because when you have a wall/object with a width smaller that that of your object, you can get stuck. Please check it out.

Hope this helps. GOOD LUCK FLASHERS!
Actionscript:
//...................................................................
//  Hero Movement
//...................................................................
onClipEvent(load)
{
	// Get the current bounds of this instance b = bounds
	b = this.getBounds(this);
	s = _root.speed;    // Dont forget to set speed variable on the main timeline
	
	function move(x,y)
	{
		if(!_root.level1.hitTest(_x + x + b.xMin+1, _y + y + b.yMin+1, true)){
			if(!_root.level1.hitTest(_x + x + b.xMax-1, _y + y + b.yMin+1, true)){
				if(!_root.level1.hitTest(_x + x + b.xMin+1, _y + y + b.yMax-1, true)){
					if(!_root.level1.hitTest(_x + x + b.xMax-1, _y + y + b.yMax-1, true)){
						_x += x;
						_y += y;
					}
				}
			}
		}	
	}
	
}
onClipEvent(enterFrame)
{	

                /* 
                The level1 variable must be replaced by the object 
                you are testing for collision detection
                */
	if(Key.isDown(Key.UP))
	{
		this._rotation = 270;
		if(!_root.level1.hitTest(_x, _y + b.yMin-1, true)){
			move(0, -s);
		}
	}
	else if (Key.isDown(Key.DOWN))
	{
		this._rotation = -270;
		if(!_root.level1.hitTest(_x, _y + b.yMax+1, true)){
			move(0,s);
		}
	}
	else if (Key.isDown(Key.LEFT))
	{
		this._rotation = -180;
		if(!_root.level1.hitTest(_x + b.xMin-1, _y, true)){
			move(-s,0);
		}
	}
	else if (Key.isDown(Key.RIGHT))
	{
		this._rotation = 0;
		if(!_root.level1.hitTest(_x + b.xMax+1, _y, true)){
			move(s,0);
		}
	}

}
  #12  
Old 01-03-2003, 08:56 PM
prisma prisma is offline

Super Moderator
 
Join Date: May 2001
Location: Munich, Germany
Posts: 1,668
Rep Power: 14
prisma is on a distinguished road
But this treats the object you move like a square.
If you move a circle its not very exact.

Actually its a bit of a cheap version of the method in my other post. Not checking for the collision of arrangable nodes, but for the the collision of the corners of the bouding box.
__________________
... take me to your coder.
  #13  
Old 11-05-2003, 11:03 PM
M2. M2. is offline
Registered User
 
Join Date: Nov 2003
Posts: 1
Rep Power: 0
M2. is on a distinguished road
Quote:
Originally posted by prisma 
I found a similar way, but maybe a bit easyer to create:
http://www.dalord.yi.org/prisma/flas...collision2.swf
http://www.dalord.yi.org/prisma/flas...collision2.fla
Thanks for the wonderful samples prisma.
__________________
Are you Dreamhosted? .. M2 .. G4 Specs
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
rollOver image - odd shape but entire square gets detected Amy_Saunders Flash MX 2004 2 08-16-2005 05:42 AM




All times are GMT. The time now is 09:51 PM.