PDA

View Full Version : Lua coding help....round 2



Man
March 18th, 2007, 18:10
ok, so i have learned the basics, and im ready to start a game or somthing extremely simple, but i cant find a guide or tutorial to add moving images, like for walking, i downloaded the "sprite" pack from here:http://www.evilmana.com/graphics/ and it has all seperate images, and i can see how they are supposed to work, but i dont know how to make them work with my player commands and such, if some one can point me to a guide or somthing, you would be helping out a lot, im really interested in making games and stuff for the psp, but i cant find out how to make these work, again, im a total noob at coding, but i do know most things and the things i dont, i will soon hopefully.

-Xandu-
March 18th, 2007, 18:20
The guide's on the same site...

http://evilmana.com/tutorials/codebase/simple_animation.php

Man
March 18th, 2007, 18:29
ahh shit, didnt see that, thanks, wow, that makes mee feel silly, but where do i put the images i want to load?
do i load them inside of the table at the top? srry, its not really a guide, its just like a code snippet, it isnt really usefull without a description on how to use it, or why.

yaustar
March 18th, 2007, 18:34
First it load the 5 animation images
animation1.png
animation2.png
animation3.png
animtaion4.png
animation5.png
and puts them into a table.
Refers to the code at the top:

-- Load Images Into A Table
animation = {}
for a = 1, 5 do
animation[a] = Image.load("animation" ..a..".png")
end

The animation code is just this which is pretty straightforward:

if pad:cross() then
if loopCount >= 0 and loopCount < 6 then anim = animation[1]
elseif loopCount >= 6 and loopCount < 12 then anim = animation[2]
elseif loopCount >= 12 and loopCount < 18 then anim = animation[3]
elseif loopCount >= 18 and loopCount < 24 then anim = animation[4]
elseif loopCount >= 24 and loopCount < 30 then anim = animation[5] end
if loopCount + 1 >= 30 then loopCount = 0 else loopCount = loopCount + 1 end
end

I can't remember how many comments I wrote for this snippet but here is an alternate way to do animations.
http://www.dcemu.co.uk/vbulletin/showthread.php?t=28021

Man
March 18th, 2007, 18:49
do the images have to be in PNG format ? or can they be in gif or anything else? and does it matter if i just want to load two images ? like these two (see attached files ) this is what i have so far :
-- Load Images Into A Table
animation = { Image.load("1.PNG") ,Image.load("2.PNG")}
for a = 1, 2 do

end

-- Player Info
player = {}
player.x = 220
player.y = 110
player.pad = "none"


-- Set Default Image
animation1 = anim

-- Set loop count
loopCount = 500

-- Read Controls
while true do
pad = Controls.read()
screen:clear()

-- Animation Loop
if pad:cross() then
if loopCount >= 0 and loopCount < 6 then anim = animation[1]
elseif loopCount >= 6 and loopCount < 12 then anim = animation[2]
elseif loopCount >= 12 and loopCount < 18 then anim = animation[3]
elseif loopCount >= 18 and loopCount < 24 then anim = animation[4]
elseif loopCount >= 24 and loopCount < 30 then anim = animation[5] end
if loopCount + 1 >= 30 then loopCount = 0 else loopCount = loopCount + 1 end
end

-- Display Default Image
screen:blit(player.x,player.y,anim)

-- End Loop
screen.waitVblankStart()
screen.flip()
end


do i have the images in the right places ?

yaustar
March 18th, 2007, 20:49
That will crash since the animation code will try to load the 3rd - 5th entry in the table which doesn't exist. Since the for loop is empty, remove it. Images HAVE to be in PNG. LuaPlayer doesn't support any other format besides PNG or JPEG.

Man
March 18th, 2007, 22:44
im so frigging frustrated with this, i cant get it to work and it seems to be a simple prosses, but i cant get it to work i removed the loops that are not needed, but it says attempt to blit player, a nil value. If anyone who has a lot of patience, walk me through this, or make a small guide or somthing, you would be my hero.

yaustar
March 19th, 2007, 00:12
-- Set Default Image
animation1 = anim
anim at this point in code doesn't exist yet so it is deemed as nil. animation1 is not used at all in the code. Remove it. This the reason why it throws the error on this line:

screen:blit(player.x,player.y,anim)
anim is nil therefore the function does a wobbly since it expects an image.

This line should be:

-- Set Default Image
anim = animation[1]
This sets anim to 'point' at the image that is stored in the first entry of the table animation.

Man
March 19th, 2007, 00:38
ok never mind, iv got it now. Thanks for all your help, your my hero.

dangee
March 19th, 2007, 10:33
if debugging and yourLuaplayerVersion>=2.0 then youMayFindThisUseful=true end