|
-
AS2 hitTest "properties"
If there was something large and odd shaped, like a triangle or a throwing star, if you only wanted the edges and the star itself rather than having the entire box that surrounds it to have a hitTest, how would it be done?
For example, there is a four pointed object: (imagine something like this)
Code:
ooooooooo
o | o
o---|---o
o | o
ooooooooo
(image may be distorted, the "o" represents the movieclip (and its box) and the lines represent the star itself. If anything inside the "o" touches something, the hitTest function will activate. Is there anyway to make is specifically target only the lines inside the "o" box?)
but only the | and - does the actual hitTest, not the "o" box that surrounds it.
Just wondering if its possible.
-
try using:
PHP Code:
if(this.hitTest(_root.star._x,_root.star._y,true){
do this
}
"this" being what ever it is you wanted to be hitting it.
-
Technically i can't really use "_root.star._x" (or y) because its being created from the library. I'm attaching a movie clip from some other movie clip (for example, _root.ship) and so there's no real directory that leads to the "star"
Hope its not too confusing.
-
Technically i can't really use "_root.star._x" (or y) because its being created from the library
wrong. The new name created in your attachMovie code is the instance name to target the dynamic mc.
gparis
-
You're right. However, It doesn't satisfy all my needs.
It works and I am grateful for that. If that star was huge, large enough that it could fill up a fourth of the screen, the collision detection and the "do this" function will work horribly.
Code:
if(_root.ship.hitTest(_x,_y,true))
{
function();
}
Where ship is the object (mobile) that is being hit by the star ("_x" represents the 'x location of the star' and same with the "_y")
Now, as a suggestion, would it be smart to, say, add values to the _x and _y depending on how large they are. Take the diagram in the first example and assume that each '|' is 10 px long and each '-' is 5. But i'm missing the top and left side hmm?
Code:
if(_root.ship.hitTest(_x+15,_y+30,true))
{
function();
}
-
I would hate to bump this but could anyone offer any advice? What i just stated below didn't seem to work and so either the huge box-like movieclip is the "detector" or the very center point.
-
You could create a hitbox inside any of these objects and make the hitbox anysize you want. That way you can control where you want objects to be hit and not.
Code:
ooooooooo
o .|. o
o---|---o
o '|' o
ooooooooo
just add hitarea or hitbox at the end of your object name.
PHP Code:
if(_root.ship.hitTest(this.hitbox._x,this.hitbox._y,true))
{
function();
}
or
PHP Code:
if(_root.ship.hitbox.hitTest(_x,_y,true))
{
function();
}
-
Thanks for the reply,
but if I were to make a huge triangle, that wouldn't work out so well would it? I would need multiple hitboxes or areas. You cannot make the hitboxes into triangles right? (That is, hit-triangles)
Having hitboxes is a good idea; their shape is still a square -- meaning that they still pose the same problem (unless you have many many hitboxes).
Any clues?
-
Well I'm no expert but I'm pretty sure this._x and this._y gets the borders of the object and not just the area of the shape itsself. Most platformer games use this for their floors so they can have one image as the floor with differnt shapes. I can't help you anymore than this since I have no more information than this. Sorry if I messed up a lot. I'm trying to post with my phone.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|