Page 1 of 1

My image is bleeding out hardly. Need an aid.

Posted: Wed Feb 11, 2015 10:18 pm
by Gad
First of all:
I just started using love2d few days ago and I really appreciate the engine (even if I didn't code in lua before, lol).

Second:
I am using older love version (0.8), since I was learning from a tutorial coworking with AdvTiledLoader and I found out that newer versions doesn't support it.



I'm trying to crop a sprite from a spritesheet.

Code: Select all

function DrawSprite(object)
	finalcut = love.graphics.newQuad(0, 0, 37, 37, object.spriteSheet:getWidth(),object.spriteSheet:getHeight())
	
	
	love.graphics.drawq(object.spriteSheet, finalcut, 100, 100)
	
end
After resizing with love.graphics.scale(2.0, 2.0), it starts to bleed.

Image

And it's not only about the frame, but the image is blurred.



I've been trying to google the answer but all I found is 'use integer positions'.
I'm pretty sure that the numbers I use to blend the images are all integers.


Yeah and I know that using quad every frame may cause jamming, I'll rework it later, but for now I need an answer - can this be fixed?

Re: My image is bleeding out hardly. Need an aid.

Posted: Wed Feb 11, 2015 11:01 pm
by Relazy
Have a look at:
https://love2d.org/wiki/FilterMode

If you are always going to use the same wrap such as in your case as your game looks based on pixel art you may want to do the following in your load function:

Code: Select all

   love.graphics.setDefaultFilter( "nearest", "nearest")
Edit:
Sorry I missed the part at which you stated you used 0.8.0 in this case your function is:

Code: Select all

  love.graphics.setDefaultImageFilter( "nearest", "nearest")

Re: My image is bleeding out hardly. Need an aid.

Posted: Thu Feb 12, 2015 8:51 am
by Gad
Thank you. This helped.

Re: My image is bleeding out hardly. Need an aid.

Posted: Thu Feb 12, 2015 10:57 am
by Tjakka5
Also, if you haven't already, modify the line where you draw your image to something like this:

Code: Select all

love.graphics.draw(player.img, math.floor(player.xPos+0.5), math.floor(player.yPos+0.5)

Re: My image is bleeding out hardly. Need an aid.

Posted: Thu Feb 12, 2015 3:43 pm
by Muris
Tjakka5 wrote:Also, if you haven't already, modify the line where you draw your image to something like this:

Code: Select all

love.graphics.draw(player.img, math.floor(player.xPos+0.5), math.floor(player.yPos+0.5)
I always thought the idea is to add 0.5 offset after flooring aka

Code: Select all

love.graphics.draw(player.img, math.floor(player.xPos)+0.5, math.floor(player.yPos)+0.5)
At least from what I tried in the past, if you draw lines on where its int value, it actually does not always draw them, but if you offset if by 0.5 it is more likely to draw lines. I am not too sure about images though

Re: My image is bleeding out hardly. Need an aid.

Posted: Fri Feb 13, 2015 12:54 am
by DaedalusYoung
Muris wrote:At least from what I tried in the past, if you draw lines on where its int value, it actually does not always draw them, but if you offset if by 0.5 it is more likely to draw lines. I am not too sure about images though
That only applies to lines and points. The int value of a pixel only points to the upper-left most point of the pixel, so drawing a line on int values actually tries to draw a line in between two pixels. If you want the line on one pixel, you have to draw it in the middle of the pixel, so at its int + 0.5 coordinate.

This does not apply to filled shapes or images, because you actually want them to be drawn from the top left position, so the 0,0 pixel of the image is on the 0,0 pixel of the screen.

Adding 0.5 before flooring actually rounds the float values to the nearest int, so it is more accurate than just flooring.