Page 1 of 1

animation help

Posted: Mon Sep 10, 2012 10:47 pm
by luislasonbra
Hi I have the following code

Code: Select all

function love.load()
   img = love.graphics.newImage("05.png")
   coord = {x = 320, y = 20}
   
   arriba = {
   imgX = 0,
   imgY = 144,
   pasos = 0}

   abajo = {
   imgX = 0,
   imgY = 0,
   pasos = 0}

   izquierda = {
   imgX = 0,
   imgY = 48,
   pasos = 0}

   derecha = {
   imgX = 0,
   imgY = 96,
   pasos = 0}
   
   dir = arriba
end

function love.update(dt)
   mov()
   pasos()
   --bordes()
end

function love.draw()
     love.graphics.draw(image, coord.x, coord.y, dir.imgX, dir.imgY) 
end

function mov(dt)
   
    if love.keyboard.isDown("up") then
       dir = arriba
       coord.y = coord.y - 1.5
       dir.pasos = dir.pasos + 1.5
    elseif love.keyboard.isDown("down") then
       dir = abajo
       coord.y = coord.y + 1.5
       dir.pasos = dir.pasos + 1.5
    elseif love.keyboard.isDown("left") then
       dir = izquierda
       coord.x = coord.x - 1.5
       dir.pasos = dir.pasos + 1.5
    elseif love.keyboard.isDown("right") then
       dir = derecha
       coord.x = coord.x + 1.5    
       dir.pasos = dir.pasos + 1.5
    end
   
end

function pasos()
   if dir.pasos >= 0 and dir.pasos < 10 then 
      dir.imgX = 0
   end

   if dir.pasos >= 10 and dir.pasos < 20 then
      dir.imgX = 32
   end
  
   if dir.pasos >= 20 and dir.pasos < 30 then
      dir.imgX = 64
   end

   if dir.pasos >= 30 and dir.pasos < 40 then
      dir.imgX = 96
   end

   if dir.pasos > 40 then
      dir.pasos = 0
   end
end
to make an animation, animations are within a png image
but it gives me error

Re: animation help

Posted: Tue Sep 11, 2012 12:24 am
by josefnpat
Hello!
  1. What is your error?
  2. You are calling mov() without the dt argument in your love.update.

Re: animation help

Posted: Tue Sep 11, 2012 3:35 pm
by luislasonbra
josefnpat wrote:Hello!
  1. What is your error?
  2. You are calling mov() without the dt argument in your love.update.
look what I want is to know how to get the different images on the image I'm using png

for example if the image has 5 pictures in like 4 of them use

excuse my English use google translator to translate

Re: animation help

Posted: Tue Sep 11, 2012 4:39 pm
by Roland_Yonaba
As Josef says, you need to describe the error.
And by the way, as Google Trad produces weird results, we may not clearly understand the problem. You'd better try to explain your problem in english, even if your english is poor (as mine, yup).. and optionnally restate the problem in your original language. Maybe someone will understand and help.

Now, concerning your problem, I'm not sure to catch the issue, but it seems you're dealing with a spritesheet. So what you might be looking for is Quads.
So, to split a unique image into a set of frames, it basically ends up making a regular table, populate it with love.graphics.newQuad and then draw what you want passing to love.graphics.drawqthe original image and the appropriate quad previously set.
Hope this helps.

Re: animation help

Posted: Tue Sep 11, 2012 5:44 pm
by coffee
you can talk in castellano if you want to explain the problem. Some of us will understand you quite well.

Re: animation help

Posted: Tue Sep 11, 2012 7:56 pm
by Zeliarden
Yo!

Code: Select all

img = love.graphics.newImage("05.png")

Code: Select all

love.graphics.draw(image, coord.x, coord.y, dir.imgX, dir.imgY) 
img instead of image?

Re: animation help

Posted: Sat Sep 15, 2012 2:17 pm
by luislasonbra
Roland_Yonaba wrote:As Josef says, you need to describe the error.
And by the way, as Google Trad produces weird results, we may not clearly understand the problem. You'd better try to explain your problem in english, even if your english is poor (as mine, yup).. and optionnally restate the problem in your original language. Maybe someone will understand and help.

Now, concerning your problem, I'm not sure to catch the issue, but it seems you're dealing with a spritesheet. So what you might be looking for is Quads.
So, to split a unique image into a set of frames, it basically ends up making a regular table, populate it with love.graphics.newQuad and then draw what you want passing to love.graphics.drawqthe original image and the appropriate quad previously set.
Hope this helps.
thanks anyway I have solved the problem.