Page 2 of 2

Re: How to group 130 png files to make an explosion?

Posted: Mon Nov 28, 2016 6:42 am
by Sir_Silver
Pretty cool, not perfect like you said but you can always make it better. Like Ivan mentioned, using particles might be a better way of trying to do what you want. I haven't used particles yet, so I won't be of much help with that, but you probably will want to look into that on your own time. :P

Re: How to group 130 png files to make an explosion?

Posted: Tue Nov 29, 2016 7:06 pm
by josefnpat
If you are looking for a tool to pack your sprites, check out urraka's texpack. Cannot plug this tool enough.

Re: How to group 130 png files to make an explosion?

Posted: Fri Dec 02, 2016 8:08 am
by paul54000
i make a test for animate a sprite but i don't understand how slow down the animation :

Code: Select all

local animation_table = {}
local current_frame = 1
local current_frame_duration = 0.5
local time_per_frame = 0.1

function love.load()
   love.graphics.setBackgroundColor(0, 20, 10)

   image = love.graphics.newImage("perso.png")  --We load the main image file that we want to animate.
   
   local image_w, image_h = image:getDimensions()
   local quad_w, quad_h = image_w / 5, image_h / 4
   
   --[[
      The width of our quad will be equal to the width of the image divided by how many frames there are horizontally.
      The height of our quad is equal to the height of the image divded by the number of frames vertically.
   ]]
   
   for y = 0, 10 do
      for x = 0, 4 do
         animation_table[#animation_table + 1] = love.graphics.newQuad(x * quad_w, y * quad_h, quad_w, quad_h, image_w, image_h)
      end
   end
   
   --[[
      This for loop allows us to offset subsections of our main image and store those subsections
      into our animation table so that we can draw it.
   ]]
   
   animation_table[#animation_table] = nil --The last image in the animation I've choosen is blank, so I remove it here.
end

function love.update(dt)
   current_frame_duration = current_frame_duration + dt
   
   if current_frame_duration >= time_per_frame then
      current_frame = current_frame + 1

      if current_frame > #animation_table then
         current_frame = 1  --If we increment passed how many frames we have, we go back to the first frame.
      end
   end
end

function love.draw()
   local x, y = love.mouse.getPosition()
   
   love.graphics.draw(image, animation_table[current_frame], x, y) 
   --Here we draw the current frame, determined in love.update, at our mouse position
end

Re: How to group 130 png files to make an explosion?

Posted: Fri Dec 02, 2016 2:14 pm
by Positive07
In order to slow it down to need to increment time_per_frame, it is the time that it takes to go from one frame to another, making it bigger will make it seem slower

Re: How to group 130 png files to make an explosion?

Posted: Fri Dec 02, 2016 2:49 pm
by Ref
To control time between sprite change I use:

Code: Select all

function setTimeDelay( delay )
	local lapsed = 0
	return function( dt )
		lapsed = lapsed < delay and lapsed + dt or 0
		return lapsed == 0
		end
	end
In love.load I put:
check = setTimeDelay( 0.1 )
and in love.update:
if check( dt ) then (what ever you want updated) end