ok… here’s where all you math genius’ get to help me out. I know that this principal is not difficult and was taught sometime during my highschool years.
I need a math formula which reduces the ratio of any x:y to the smallest quanity possible. Basicaly so that the smaller of the two numbers is 1 and the other number is whatever it would be, compared to 1… but, I need it to work for both posative and negative numbers.
(I’m the ultimate Math newb… bear with me)
so. I have x=20, y=20 is 1:1
-20, y=-10 is -2:-1
x=10, y=-5 is 2:-1
ect.
so what is the formula for that? my mind is blank today… between alergies and a cold… I can’t think of this for the life of me.
Looks similar to something I’ve been fiddling with. Really I’m just trying to figure out wether I’m over thinking it, and in fact it’s some silly formula that every first year Algebra student knows. I’m glad I wasn’t that far off.
I’ll continue to write the code as I am working on it. If you see some redundencies, let me know.
the statement in the second line is… i forgot what it’s called, but it works kind of like an if-statement…
(password = "sesame") ? trace("correct password") : trace("password is incorrect")
// if the expression in brackets is true, trace
//"correct password". If not, trace "password is incorrect"...
ok… I looked up both of those and I think I understand what’s happening… however… don’t you need to set the absolutes first and switch the “if for reverse” check to the end like so?
*Originally posted by david *
**ok… I looked up both of those and I think I understand what’s happening… however… don’t you need to set the absolutes first and switch the “if for reverse” check to the end like so?
**
Only when doing the comparison between x and y do we need the absolute values. Later on, the numbers need to retain their value.
I’m not sure about switching the ‘if for reverse’. It works fine the way it is, and might work just as well if you switched them. Try that and tell me how it goes
Math.min and/or Math.max could be used, but they wouldn’t optimize the code anywho. Using Math.min would look like this:
What I’m attempting to do is send out a signal, from the ball, in the direction indicated by the ratio, to the edge of the board, and to test for each location. If there is a hit indicated with an object, then the ping returns a maximum x and y distance to travel (ensuring that a ball moving at 20 pixels per click will not move past an object that is only 10 pixels in size, without registering a hit.
I may also, rather than using a hitTest, opt to keep track of all the locations of objects in an array, and then test against that instead. I may find this will work better… but as I haven’t even gotten the ping to register correctly, I don’t know yet.
I’ve been trying to use a while loop
Something like this
For a case like this I would achieve it through a tile-based approach. Although your way seems logical enough, and more flexible/accurate in some ways
[edit]
*Originally posted by david *
**to keep track of all the locations of objects in an array, and then test against that instead. I may find this will work better… **
yeah… that’s what i was talking about
as for “flexible/accurate”… yeah I know what you mean… I’m really creative when it comes to figuring out how this stuff should be done. Unfortunately I’m not nearly as good at figuring how how it must be done… if you know what I mean.
My way seems well suited for a compiled programming language like C… it’s sad that Flash can’t handle nearly as much data control.
*Originally posted by david *
**Is it any faster to loop through an array’s data than to loop through all objects in the _root through a for in loop with hitTest? **
I’ve read somewhere that flash stores all objects in the arrays _root (or _this and _parent), so when you’re looping through arrays on either cases, whether you store the data in an array or use the movie’s built-in array… "(References to) MC’s, variables, etc (all objects basically) are stored inside an associative array on the timeline they’re on. "
*Originally posted by david *
**as for “flexible/accurate”… yeah I know what you mean… I’m really creative when it comes to figuring out how this stuff should be done. Unfortunately I’m not nearly as good at figuring how how it must be done… if you know what I mean.
My way seems well suited for a compiled programming language like C… it’s sad that Flash can’t handle nearly as much data control. **
Yeah, a tile-based approach kind of limits you in a way that there are no ‘in-betweens’… you’re either on this tile or another one. On my current project, I’m moving objects 2 pixels/frame, and the tile size is 17 pixels … that’s causing a lot of headache :-\