by [KHK]Khalid Sat Jun 22, 2013 5:39 am
Hmm this might work (and fix the only one axis problem) if I clearly understood what you said.
Make 2 more variables for
personaje - Code:
personaje.lastFreeX
personaje.lastFreeY
We will run a repeated timer (or maybe use the main process thread where you're checking if hitTestObject and these stuff) (With interval 500 ms maybe? I dunno this needs some experiments to make it work properly) and we'll be storing
personaje's X (AS LONG AS hitObjectTest returns FALSE (i.e it doesn't overlap an object)) in its
personaje's lastFreeX, same goes to Y and lastFreeY. And then we can use LastFreeX/Y to return
personaje when it overlaps
muro to its last position where it was right before overlapping . Here's an example of what I said, there may be some syntax errors:
- Code:
theTimer() // or main thread
{
if(!personaje.hitTestObject(muro)) // Using "!". If personaje isn't overlapping muro.
{
personaje.lastFreeX = personaje.x;
personaje.lastFreeY = personaje.y;
}
else // Else. If it's overlapping muro .. same as if(personaje.hitTestObject(muro))
{
// reset its position to the last FREE position we stored.
personaje.x = personaje.lastFreeX;
personaje.y = personaje.lastFreeY;
}
}
If this doesn't work, come back and show me the code you've wrote for it and we shall workout it. I think the only thing that can make it fail is the interval of that timer as it doesn't have to check/store the x/y and lastFreeX/Y MANY times nor FEW times.