int tileX = static_cast<int>(entity.x / tileSize);
int tileY = static_cast<int>(entity.y / tileSize);
I see trouble unless you limit it to positive numbers. -1 should always be in tile -1 but ends up 0 unless you add special handling for negative coordinates.
Shouldn't the left side be:
insideX = (temp.x + 32) - getX(); (the right block edge minus the objects left edge
setX(temp.x + insideX); (the right block edge plus the amount you have to bounce back)
The numbers in your code confuse me. Where did 24 come from? Why the additional -32 after colliding to the right?
Wait, I noticed one bug in my code. You need to
setX(temp.x - 2*insideX)
(once to move "out" of the block, twice to where you should be after bouncing back)
So the fixed collision to the left would be:
setX(temp.x + 2*insideX)
And to exploit the neatness of math
if (hspeed > 0)
insideX = (getX() + 32) - temp.x;
else
insideX = getX() - (temp.x + 32);
//or more compact and confusing: insideX = getX() - temp.x + (hSpeed * 32);
setX(getX() - 2*insideX);
edit: damn non-descriptive names. getX, not temp.x