all groups > flash actionscript > january 2004 >
You're in the

flash actionscript

group:

Some help with coordinates please!



Re: Some help with coordinates please! tralfaz
1/18/2004 4:25:44 PM
flash actionscript: [quoted text, click to view]
the scene (I think it's a fish). There are also a few barriers around on the
scene. When this fish or something swims into one of these barriers, it is
supposed to activate a movie clip when the x and y values of the fish match
the values of the x and y for the barriers.
[quoted text, click to view]

See some examples at flashkit:
http://www.flashkit.com/tutorials/Games/

hittest can be used to detect collision of an object with a barrier.
// see if the ball has hit the square
if(_root.ball, hittest(_root.square)){
trace("ball intersects square");
}

Some help with coordinates please! happyblimp
1/18/2004 11:16:08 PM
Hullo!

Ok, so, I have this friend (clichè? no, no, I swear it's true!) that has a problem. I thought i could help her but I couldn't after all.

So the problem is: she has this thingamajig that you can guide around on the scene (I think it's a fish). There are also a few barriers around on the scene. When this fish or something swims into one of these barriers, it is supposed to activate a movie clip when the x and y values of the fish match the values of the x and y for the barriers.

Waiting in suspense
....

Re:Some help with coordinates please! Pea
1/19/2004 3:04:30 AM
um, hi,

Tell "your friend" that this may be interpreted in two ways:

First of all, each clip (the fish and the barrier) have a reference point which is usually the center of the clip, and this point is usually what people refer to as the x,y coordinate of the clip, so, the interpretations are:

1) You (I mean, "your friend") wants the x,y values of the fish to line up exactly with the x,y values of the barrier, which would mean that the movie clip is activated when the middle of the fish lines up with the middle of the barrier. I doubt this is what you want...

2) Your friend wants some rudimentary collision detection to determine when the fish hits the barrier at all (e.g. The nose, or the tail, or the fin). SO I will explain this one:

The easiest way is to define a 'bounding box' for each object. Define a box (and the coordinates of it) that surround the fish. Also define one that surrounds the barrier. Once this is done, collisions are detected if these two boxes ever intersect.

You can either:
a) Call this function from the main timeline, passing if the values of the fish and each barrier to check for a collision in turn - or -
b) Contain this function inside the barrier itself. The function checks for a collision between the fish (of which we presume there is only 1) and the barrier clip from which the function is called.

I recoomend (b) if there are few barriers because then collsion detection is automatic and you can simply drop in more barriers with no extra code. But if there are too many barriers, the function will be run inside each barrier and slowr computers will have a hard time coping.

Hope it helps,
Pea

AddThis Social Bookmark Button