Hi All
Im doing a project for uni, and im stuck. I have a little experience with AS3, but not enough to figure this out myself.
My task is to get some circles to move randomly within a certain area. Im imagining using math.random and hitTestObject (if you have any other suggestions they would be most welcome). To be more exact, this picture is what it is all about:
Im receiving data from another program (lets say Int numbers from 0-100) and i want to use these numbers to decide the speed of the circles, who should move randomly,but within their ‘area’. By this i mean that the white circles stay on the black background and vice versa.
If anyone has any concrete solutions, or ideas on how to get this working i would very much appreciate it!
Thanks,
Esben
I would suggest separating the black and white areas into 3 separate regions:
1.) White Center
2.) Black Center
3.) Black Border
Now you can do a hitTest against each as is needed. Then the white circles would be doing a hitTest against the white region. If they hit it, have them reverse their direction. Same with the black circles in the white area, only they will be doing a hitTest against both the black border and the black are, and reverse their direction as well.
Hope that helps!
-BahamutZaero
Thank you BahamutZaero, I will try to fiddle around with that now. I was hoping for an answer like that.
Now i need to get it to work…
Esben
OK, i have tried to follow your advice Bahamut, but am in problems yet again. I have importet the model from photoshop on different layers (1 outer ring, 1 white area, 1 black area). The problem is then, that upon converting the outer ring to a movieclip, everything inside it be contained in that movieclip. This means that if i hittest against my outer ring it will return true as long as the object im hittesting with is inside the outer ring.
Does this make sense? Ive tried other things, but have found no solutions. Please help,
Esben
I’d make the two circles an abstract object instead of a movieclip. A circle can be represented by a centre point and a radius.
Your white and black circles will have a centre point and a radius - this is all you need to check to see if a circle is about to move out of its designated area - you just check the distance of the circle from a centre point.
Hi Charleh, thanks for your reply. Im not sure i understand excactly what you mean. Do you suggest that i make the small circles that i want to move around abstract objects? I thought the problems was with the designated area?
What i figured out is this: When i turn the outer ring into any other object than ‘shape’ a square will form around it, and anything contained in that square will hitTest true when i check. Im really sorry but i dont understand how knowing where the circle is can help me, if i can only check against a square area.
Esben
Edit: I have now experimented with hitTestPoint instead. This seems to work when i check for mouseX and mouseY. However it will not work with my movieclip object. Heres the code:
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]mc.[COLOR=#000080]hitTestPoint[/COLOR][COLOR=#000000]([/COLOR]mouseX, mouseY, [COLOR=#000000]**true**[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]"hit!"[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000]}[/COLOR]
This works fine when testing with a circle whith an inner radius which was then converted to a movieclip, while this
if (Yderring_mc.hitTestPoint(event.target.X, event.target.y, true)) {
trace("hit!")
}
will not work at all. Any ideas?
thanks, Esben
OK, it seems that this was the correct code to use
if (Yderring_mc.hitTestPoint(Cirkel1_mc.x, Cirkel1_mc.y, true)) {
trace("hitter")
}
It was not excactly what i was looking for, but it will have to do. Thanks for your help guys.
Esben