I've got a problem. I'm xant to make a 2D scrolling game, but I can't figure out how to change the sprite when going in an opposite direction. Here's the code :
require("AnAL")
function love.keypressed(key)
if (key == "right") then
anim:seek(1)
end
end
function love.keypressed(key)
if (key == "left") then
anim:seek(14)
end
end
function love.load()
img = love.graphics.newImage("perso.png")
bg = love.graphics.newImage("bg.png")
anim = newAnimation(img, 170, 400, 0.1, 13)
x = 0
end
function love.update(dt)
if love.keyboard.isDown ("right") then
anim:update(dt)
x = x + 2
elseif love.keyboard.isDown("left") then
anim:update(dt)
x = x - 2
end
end
function love.draw()
love.graphics.draw(bg)
anim:draw(x, 100)
end
I've got a sprite sheet named "perso" containing 13 sprites of the character moving right, and 13 sprites of him moving left, so how do I do to switch sprites when changing the pressed button ?
love.graphics.draw ( sprite, x, y, -1, 1 ) --latter two are X and Y scale, negative X scale does horizontal flipping. Play around with it to see how it works
Yeah, why is the third argument rotation? That would imply that more people use just rotation than they use scaling and offsets, and I think this is far from the truth...
Kingdaro wrote:Yeah, why is the third argument rotation? That would imply that more people use just rotation than they use scaling and offsets, and I think this is far from the truth...
I often use rotation and seldom use scaling actually
According to what slime said, arguments order in drawing function is exactly the order specified transformations are applied before rendering. In following example, both snippets yield same result:
love.graphics.draw ( sprite, x, y, r, sx, sy, ox, oy, kx, ky )
--====--
love.graphics.translate ( x, y )
love.graphics.rotate ( r )
love.graphics.scale ( sx, sy )
love.graphics.translate ( ox, oy )
love.graphics.shear ( kx, ky )
love.graphics.draw ( sprite ) --implying you can omit X and Y
If you don't certain arguments, you can just pass nil for them.
Well, now it's helpful for a rotation and stuff, but now, if I want it to jump, i'll have to "hide" the current sprite and replace it by another one. How do I achieve this ?