love.graphics.translate, how to use?

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
vadim2
Prole
Posts: 7
Joined: Sun Jan 03, 2010 9:20 am

love.graphics.translate, how to use?

Post by vadim2 »

Maybe someone can give an example of a function, I do like this:

Code: Select all

if love.keyboard.isDown("up") then
love.graphics.translate(0,0.2)
end
But it does not work.
User avatar
walesmd
Prole
Posts: 22
Joined: Fri Oct 08, 2010 3:11 am
Location: Augusta, GA
Contact:

Re: love.graphics.translate, how to use?

Post by walesmd »

All translate does it alter future drawing operations. Easier to explain in code:

Code: Select all

function love.draw()
  local x = 10
  local y = 10

  love.graphics.point(x, y) -- This point is drawn at 10, 10
  love.graphics.translate(20, 20)

  love.graphics.point(x, y) -- This point is drawn at 30, 30 thanks to translation. We didn't change the x, y variables.
end
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: love.graphics.translate, how to use?

Post by vrld »

You need to do this in your love.draw() function. So you probably want to do something like this:

Code: Select all

local ty = 0
function love.draw()
    love.graphics.translate(0,ty)
    ... other draw stuff ...
end

function love.update(dt)
    if love.keyboard.isDown('up') then 
        ty = ty +  0.2 -- this is framerate dependent! use ty = ty + 10 * dt to make it move 10 pixels per second
    end
    ... other update stuff ...
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
vadim2
Prole
Posts: 7
Joined: Sun Jan 03, 2010 9:20 am

Re: love.graphics.translate, how to use?

Post by vadim2 »

Tnx all!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests