Taerzik -> RE: Flash Q&A Thread 5 - Flash Has Shares In Your Soul (9/16/2008 9:41:00)
|
if (_root.walls.hitTest(getBounds(_root).xMax, _y, true)) {
_x -= myBounce;
}
if (_root.walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += myBounce;
}
if (_root.walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= myBounce;
}
if (_root.walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += myBounce;
} Ok Nicky, lemme see here: '_root.walls' are, obviously , your wall mc(s), which are 'hitTest'ing with your character. 'getBounds' is basing the data it returns (four coordinates: xMin, xMax, yMin, yMax) off of the '_root'. The reason that this is important is if you had nested clips the returned values could be based off a parent rather than _root and would be different. So in near plain English, the first two/three lines say, "If the point at this object's 'xMax' (figured from '_root') and '_y' (so xMax,_y is the x,y of the point being checked on) bumps into the wall, this object's x position is reset to it's current x minus the value of myBounce." That clear? Seph. almost had it right. If you are confused think of it this way: xMin = actual _x yMin = actual _y xMax = actual _x + width yMax = actual _y + height That may be dependant on the content of the mc being at 0,0 in the mc. I don't remember.
|
|
|
|