
Welcome Guest
|
|
|
#1
|
||||
|
||||
|
How can detect the moon shape and square are collision ?
|
|
#2
|
||||
|
||||
|
nobody reply ...
|
|
#3
|
||||
|
||||
|
Hi Dndb, welcome to flashmove,
You need to use the 'MovieClip.hitTest()' method. swoop |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
Thx a lot !
I have learn a good idea from you "swoop" ! |
|
#7
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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.
|
|
#10
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
|
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |





