PDA

View Full Version : Help with animating PNG files



MasterChafed
July 2nd, 2006, 01:07
I am haivng trouble incorporating png files into my lua script. I currently can load them into a table, like so.

player = {}
player[1] = Image.load("1.png")
player[2] = Image.load("2.png")
player[3] = Image.load("3.png")
player[4] = Image.load("4.png")
player[5] = Image.load("5.png")

but how do I go about printing them to the screen? Blitting them doesn't work because it is for single images and when i try it it tells me that it cannot blit "player" because it is a table. thx for any input.

MasterChafed
July 2nd, 2006, 02:06
p.s. this is very urgent as I was wanting to push out a concept release of my game by tommorrow. Also, if you can give me some pointers of how to make gravity so i can jump, that would be great.

Sumo X
July 2nd, 2006, 03:16
I can't help you with the animations, as I'm not that far yet in my learning.

However, I suggest you use PSP Millionaire's Lua tutorials, as they're simply awesome, for the gravity issue.

You can find his tutorials at evilmana.com

The site was hacked not too long ago, and most of the tutorials are up now. But the one for jumping (which includes gravity) is not yet. Thanks to Google cache, we still have access to it.

http://66.102.7.104/search?q=cache:v5-n0OfUe3oJ:www.evilmana.com/tutorials/lua_snippet_jumping.php+&hl=en&gl=us&ct=clnk&cd=1

That will display the tutorial for you. He said that by tomorrow, all the tutorials should be back up on his site, so just go to evilmana.com starting sometime tomorrow or the day after.

Good luck! Hopefully somebody else can help you with the animations.

EDIT: I suggest you do the tutorial first, and see the final result before putting into your game. You may want to play with the gravity to your liking, and it's far easier to do it when you know the code is correct.

MasterChafed
July 2nd, 2006, 03:29
Thx a lot. I have been waiting for evilmana to come back up for a few days now, it really sucked finding a site with all the tuts i need and it being down. lol. thx man.

JNJC
July 4th, 2006, 06:28
Here is a function I put together to display an sequence of .png files.


function ShowAnimation (FileName,px,py,Frames,Time)

local WaitTime = Time / Frames
local AnimationTimer = Timer.new()
local img

img = Image.load(FileName .. "1.png")

for i = 2, Frames + 1 do

-- clear the screen and display the current imag
screen:clear(Color.new(255,255,255))
screen:blit(px,py ,img, 0, 0, img:width(), img:height(), true)
screen.waitVblankStart()
screen:flip()
AnimationTimer:reset()
AnimationTimer:start()

-- Load the next image and the wait until it's time to display it
if i <= Frames then
img = Image.load(FileName .. i .. ".png")
end -- if i <= Frames then
while AnimationTimer:time() < WaitTime do

end --

AnimationTimer:stop()
end -- for i = 2, Frames do

-- not 100% sure if this is needed as img is 'local' but
-- better safe then sorry
img = nil
end -- function ShowAnimation (FileName,px,py,Frames,Time)


Use it as follows:


ShowAnimation("ts",30,30,10,1500)

This will display a sequence of 10 .png files called
ts1.png
ts2.png etc..

at position 30, 30 on screen

over a period of 1.5 seconds

I don't think it's exactly what you want but it might give you a start....

MasterChafed
July 4th, 2006, 06:33
thanx anyway man, I now have a method of animating png images. Hey you should check out the game I am developing, its called Halo 2d. Check it out.