animation help

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
luislasonbra
Citizen
Posts: 60
Joined: Sun Jun 24, 2012 1:57 pm

animation help

Post 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
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: animation help

Post by josefnpat »

Hello!
  1. What is your error?
  2. You are calling mov() without the dt argument in your love.update.
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
luislasonbra
Citizen
Posts: 60
Joined: Sun Jun 24, 2012 1:57 pm

Re: animation help

Post 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
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: animation help

Post 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.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: animation help

Post by coffee »

you can talk in castellano if you want to explain the problem. Some of us will understand you quite well.
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: animation help

Post 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?
User avatar
luislasonbra
Citizen
Posts: 60
Joined: Sun Jun 24, 2012 1:57 pm

Re: animation help

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests