collisions and matrix stack [SOLVED]
When rendering my game i use a matrix stack to translate the scene coordinates while keeping the player at the center of the screen. So far so good.
When rendering the map elements I also render a rect with boundaries representing the limits I'm trying to use to detect collisions. The rects have alpha set to 0% unless I want to set it to a nice semi-transparent lime green during the game using a key that changes their alpha variable. Bellow are some demonstration screenshots (note that my bizarre z_index layering method is working \o/):
After implementing a collision detect function based in this method ( https://forum.processing.org/topic/simple-collision-detection-21-9-2012 ) I can't seem to detect the collisions, unless I stop tracking the camera and don't use the matrix stack anymore, but if doing so, there goes my screen scrolling.
My map elements are rendered in a function that reads a series of coordinates from an Array (previously fed by a text file) and draws their images. Bellow is the code:
- for (fores=0; fores<layer1.size(); fores++)
{
latlong = oTile.setSprite(layer1.get(fores).getType());
image (latlong, pix2unit(layer1.get(fores).getX()), pix2unit(layer1.get(fores).getY()));
g.removeCache(latlong);
if (layer1.get(fores).isColideable())
{
fill (55, 255, 55, boundsAlpha);
rect(pix2unit(layer1.get(fores).getX())+layer1.get(fores).pushX(), pix2unit(layer1.get(fores).getY())+layer1.get(fores).pushY(), layer1.get(fores).get007X(), layer1.get(fores).get007Y());
}
}
Let me explain.
First I probe what image should be drawn (latlong = yadda yadda...)
Draw the image
clear cache
check if the element (not the image) is set as having collisions
draw a rectangle that i'm trying to use as a collision map
*pix2unit multiplies my coordinates per 32 so my map file can be a lot cleaner.
*² – get007 is just a joke, it's my boundaries getter function. (get bounds, get bond, get 007).
Ok, in my draw function I first check the keyboard's input, push a matrix, call the render function, translate coordinates according to the input, pop the matrix, finally render the player. I'm using an int to track any collisions but not a single one is registered, however, if I manually feed the collision check function with overlapping coordinates (first rect coordinates manually set, second rect gotten from my array), if registers as it should.
So, is the matrix stack the reason I'm having such problem? And, if so, any suggestions about how to fix it. Finally, is this the best way to scroll the screen so the player characters will be followed?
Ok, thank you all in advance :)