Hey guys. I got a problem about drawing images. At the first picture, there is no bug in our character. but after you move it a little, with (x=x+100*dt) there is a slightly white border which appears. also it loses all smoothness it has. how can i solve it? all my pictures are png formatted.
Image bug
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Image bug
Linear filtering happens because you're moving the image to sub-pixel positions. Use
Code: Select all
x = math.floor(x + 100 * dt)
- zorg
- Party member
- Posts: 3449
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Image bug
With the above code, if the speed would be lower, the character may not move at all;
What you want instead, is to move it without flooring, but floor the coordinates when drawing.
What you want instead, is to move it without flooring, but floor the coordinates when drawing.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Image bug
thanks for help but i think this only works at left and top directions. at the other directions it can't move.
Re: Image bug
zorg is right, it wouldn't work at lower speeds or very high frame rates. My bad.
Please show some code. Only the relevant code please: the part where you're moving your sprite and the part where you're drawing it.
Please show some code. Only the relevant code please: the part where you're moving your sprite and the part where you're drawing it.
Re: Image bug
-walking part
Drawing part (while it walks or stops frames change)
lp means love.graphics.
Code: Select all
if love.keyboard.isDown("d") then
woo.x=woo.x+200*dt;
woo.lastKey="right";
woo.active="right";
elseif love.keyboard.isDown("a") then
woo.x=woo.x-200*dt;
woo.lastKey="left";
woo.active="left";
elseif love.keyboard.isDown("w") then
woo.y=woo.y-200*dt;
woo.lastKey="top";
woo.active="top";
elseif love.keyboard.isDown("s") then
woo.y=woo.y+200*dt;
woo.lastKey="bot";
woo.active="bot";
else
woo.active="idle";
end
Drawing part (while it walks or stops frames change)
Code: Select all
if woo.active=="idle" then
lp.draw(img.woo.idle[woo.kare], woo.x, woo.y);
elseif woo.active=="right" then
lp.draw(img.woo.sag[woo.kare], woo.x, woo.y);
elseif woo.active=="left" then
lp.draw(img.woo.sol[woo.kare], woo.x, woo.y);
elseif woo.active=="top" then
lp.draw(img.woo.top[woo.kare], woo.x, woo.y);
elseif woo.active=="bot" then
lp.draw(img.woo.bot[woo.kare], woo.x, woo.y);
end
Re: Image bug
Change all occurrences of woo.x and woo.y in the drawing part to math.floor(woo.x) and math.floor(woo.y).
Simplify your draw function
Simply it further by using the same identifiers for right and left in all places
Simplify your draw function
Code: Select all
-- untested example code, may contain errors
local anim = {
idle = img.woo.idle,
right = img.woo.sag,
left = img.woo.sol,
top = img.woo.top,
bot = img.woo,bot,
}
lp.draw(anim[woo.active][woo.kare], math.floor(woo.x), math.floor(woo.y))
Re: Image bug
It works very nicely, thanks!grump wrote: ↑Thu Sep 21, 2017 7:39 pm Change all occurrences of woo.x and woo.y in the drawing part to math.floor(woo.x) and math.floor(woo.y).
Simplify your draw functionSimply it further by using the same identifiers for right and left in all placesCode: Select all
-- untested example code, may contain errors local anim = { idle = img.woo.idle, right = img.woo.sag, left = img.woo.sol, top = img.woo.top, bot = img.woo,bot, } lp.draw(anim[woo.active][woo.kare], math.floor(woo.x), math.floor(woo.y))
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests