Page 1 of 1
Error when mirroring image?
Posted: Sun Sep 14, 2014 6:36 am
by ForeverDevv
I mirrored an image for when the player walks backwards. This causes the image to appear outside of the positioning of the player, which messes up the collision detection.
Is there any way to fix this?
Re: Error when mirroring image?
Posted: Sun Sep 14, 2014 7:13 am
by Ortimh
Give the code that creates the error for better understanding of your problem.
Re: Error when mirroring image?
Posted: Sun Sep 14, 2014 8:51 am
by bartbes
Because the image is scaled negatively, it appears on the other side of the coordinates, yes. You could adjust for this by changing the offset too (to the top-right corner, to be exact). Basically, with a positive scale, your image goes from (x, y) to (x+w, y+h), and with a negative x scale it goes from (x, y) to (x-w, y+h).
Re: Error when mirroring image?
Posted: Sun Sep 14, 2014 8:58 am
by Zilarrezko
ForeverDevv wrote:I mirrored an image for when the player walks backwards. This causes the image to appear outside of the positioning of the player, which messes up the collision detection.
Is there any way to fix this?
As Ortimh said. Seeing the code, helps us immensely. Otherwise we have to figure out all the cause that would associate with your problem, Then have to list them all out, and tell how to fix them.
For example it could be a rotation issue... If you're using rotation. In which case you could either do an algorithm to create update the collision box so that way you can rotate it all you want, and it updates the player's collision box based on a rotation matrix. But that may be a bit of a hassle for those who don't know matrices, so instead you could make that image have set facings, so when it display's that face, then it uses an offset for the collision detection, this might be the easiest implementation to understand, but probably the sloppiest. Or maybe you're using image pixel manipulation using image data, in which case your algorithm might be a bit off. It may even be as what bartbes said even. But then again, we have to think about your game's functionality. Is it top-down view? is it side? is it isometric? Heck... is it 3D (In which case not many people in the forums can help there)? [Although I would infer it to be side view, platformer style, and you said "backwards"]
To be very honest, upload a .zip, or .love, It's the best way for us to help you, as we still don't know the problem's details.
Hope you understand why man haha, We'd love to help, but we need more info.
Re: Error when mirroring image?
Posted: Sun Sep 14, 2014 2:56 pm
by ForeverDevv
Ah, okay. Here is my code.
Code: Select all
--setImageSize just set's an image's size in pixels. (returns scale x and y)
function player.draw()
love.graphics.draw(player.image, player.x, player.y, 0, setImageSize(player.image, player.sx * flip, player.sy), flip == -1 and player.sx or nil)
end
--inside of player.move()
for key, v in pairs(player.controls) do
if love.keyboard.isDown(key) then
player[v[1]] = player[v[1]] + v[2] * dt
if key == "d" then
flip = 1
elseif key == "a" then
flip = -1
end
end
end
Re: Error when mirroring image?
Posted: Sun Sep 14, 2014 3:02 pm
by ForeverDevv
Actually I just figured it out. Thanks for the help!