all groups > flash (macromedia) > october 2007 >
You're in the

flash (macromedia)

group:

MovieClip hitArea Problem



MovieClip hitArea Problem heynumber2
10/6/2007 7:59:30 PM
flash (macromedia): Hello

For some time I have been doing simple games and websites in flash.

But when I make an object, a circle for example, and then put it in a
MovieClip the hitarea of the MovieClip becomes a Square [b]INSTEAD[/b] of a
Circle. If I for instance would want to use this circle for an hitTest this
becomes an major bug/problem in a game. I hope you understand my problem and
I'm grateful for any answers.

/Kim


Re: MovieClip hitArea Problem clbeech
10/6/2007 8:17:01 PM
you need to use the 'shape based' hitTest method, where you compare a
coordinate point to the shapeflag of the MC object. this would be done like so
using the mouse point:

stop();

//with an instance of 'circle_mc' on the Stage

onEnterFrame = function() {
if(circle_mc.hitTest(_xmouse, _ymouse, true)) {
circle_mc._alpha = 50;
}else{
circle_mc._alpha = 100;
}
}
Re: MovieClip hitArea Problem heynumber2
10/6/2007 8:34:47 PM
Thanks for the quick reply. I don't think I understand this correctly, I
changed the code but it doesnt work. I hope you undestand what I want to do
when you se the code.



stop();
//with an instance of 'circle_mc' on the Stage

circle_mc.onPress = function(){
startDrag(this);
}
circle_mc.onEnterFrame = function() {
if (circle_mc.hitTest(_root.square_mc._x, _root.square_mc._y, true)) {
circle_mc._alpha = 50;
} else {
circle_mc._alpha = 100;
}
};
Re: MovieClip hitArea Problem clbeech
10/6/2007 9:50:28 PM
OK, you have to think in terms of a single 'point' coordinate, just a one pixel
position, based on one mc or point, although you could loop through the pixels
of a BitmapData object based on the circle, or use a perimiter calculation for
a circle, neither are particularly fast.

It looks above as though you are trying to place the circle into a square, or
you may be trying to use a shape based test to determine if the circle touches
the square at any point? This is different, and there are a few methods to do
two-shape hit testing, but there is not a native function in Flash to do so.

Look up Grant Skinner's collision detection class:
http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html

But there are other ways to accomplish similar things, depending on what your
try to achieve, if your looking to satisfy a condition when the circle is
completely within the square, you may be able to use getBounds() methods and
compare Max and Min properties.

Now there are a few things about you code that you should change to get it to
function. the x, y coordinates your using here are based on the registration
point of the square_mc, unless you centered the r-point, it will be in the
upper left corner. So it will only register a 'hit' when the edge of the
circle_mc comes in contact with that point.

OK so here's an example of a looping test. Since the second shape is a
square, you can simply loop through all of the pixel coordinates of the square,
to check the entire shape, although again, this is very slow processing and
there are better methods, but this is a simple one that will give you the idea.
here's the file: http://www.beechstudios.com/shapeTest.zip
Re: MovieClip hitArea Problem heynumber2
10/7/2007 12:22:16 AM
Re: MovieClip hitArea Problem clbeech
10/7/2007 4:41:57 PM
AddThis Social Bookmark Button