Error when mirroring image?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ForeverDevv
Prole
Posts: 9
Joined: Sat Sep 13, 2014 10:20 pm

Error when mirroring image?

Post 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?
User avatar
Ortimh
Citizen
Posts: 90
Joined: Tue Sep 09, 2014 5:07 am
Location: Indonesia

Re: Error when mirroring image?

Post by Ortimh »

Give the code that creates the error for better understanding of your problem.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Error when mirroring image?

Post 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).
User avatar
Zilarrezko
Party member
Posts: 345
Joined: Mon Dec 10, 2012 5:50 am
Location: Oregon

Re: Error when mirroring image?

Post 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.
ForeverDevv
Prole
Posts: 9
Joined: Sat Sep 13, 2014 10:20 pm

Re: Error when mirroring image?

Post 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

ForeverDevv
Prole
Posts: 9
Joined: Sat Sep 13, 2014 10:20 pm

Re: Error when mirroring image?

Post by ForeverDevv »

Actually I just figured it out. Thanks for the help!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests