Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Does alpha in images work in windows lua player? Because in mine it doesn't, but the same file works on ...
-
04-30-2007, 12:03 PM #7141QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Does alpha in images work in windows lua player?
Because in mine it doesn't, but the same file works on my PSP.
Is it my windows lua player or do they all do this.
To elaborate it works somewhat, but only in fully transparent areas, those semi transparent areas are drawn solid.
++EDIT++
One more question.
Does bliting something outside the 0-480, 0-270 coordinates acutely blit it to the offscreen buffer?
Is it necessary to use something like
or is it handled internally buy the blit function?Code:if x >= 0 and x < 480 then screen:blit(x,y,image) end
Geändert von radioactive_X (04-30-2007 um 12:26 PM Uhr)
-
04-30-2007, 12:37 PM #7142QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ill answer the first question: lua player windows has some problems with alpha layer, for me color (255,255,255,127) dint work in PC but worked in PSP
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
04-30-2007, 12:39 PM #7143QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
As, for the second, blit where ever you want. You just won't be able to see it if it is past 480(x) or 272(y).
-
04-30-2007, 01:12 PM #7144
when blitting offscreen using negative coords, if you go more than the screen size the image won't be blitted.
-
04-30-2007, 01:14 PM #7145QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
That is lua specific correct? For that is not the case in C.
-
04-30-2007, 01:34 PM #7146Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
The lua blit function was written in C, so technically it does do it in C. But it is an interesting question, does lua skip the blitting process automatically if an object is offscreen, or does it still allocate resources to something that the user will never see?
-
04-30-2007, 01:45 PM #7147QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Actually, LuaPSP was written in C++. And it is fairly easy. Just check if the x and y of the image are on screen, then blit if they are. I did it in a tile engine I made.
-
04-30-2007, 02:06 PM #7148QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
So I should use the above code?
I'm sorry your answers are a little conflicting.
Merick says that it won't be blited PSPJunkie says it will be blited
Because if its like Merick is saying an image wont be blited even if only the top left part went out of screen (like text does) or does the blit function use a buffer zone with image:width() and height() to make sure that doesn't happen?
I'll do some test when I have some time.
++EDIT++
I just did this test
And what happened is:Code:test = Image.load("bg.png") timer= Timer.new() timer:start() for i = 1,100000 do screen:blit(-1000,-1000,test) end timer:stop() screen:print(100,100,timer:time(),Color.new(255,255,255)) screen.flip() screen.waitVblankStart(100)
Whole image out of screen(100.000): 32-41
One pixel of image in screen(100.000): 47-63
Quarter of image displayed(only 10.000 repetitions):4267
Whole image in screen(only 10.000 repetitions): 19128
(I did this on my PC)
Does this mean that whenever we use blit it affects performance per pixel show, because I think the first two times were just the counter counting to 100.000.
Any thoughts?Geändert von radioactive_X (04-30-2007 um 02:29 PM Uhr)
-
04-30-2007, 02:43 PM #7149
what I'm saying is that if you had an image that was larger than the screen size, let's say 500x500, if you tried to blit it at -479 x -271 the image would be blitted and you would still be able to see the part of the image that's supposed to be in the visible screen area, but if you went further than that, -500 x -500, the image will not be blitted.
even if it doesn't show the image, it does take a small amount time for the lua player do it's internal checks on the image, so yes you should use a check to see if the image will be shown.
----Code:if x >= -image:width() and -image:width() > -480 then screen:blit(x,y,image) end
In this code, can anyone tell me why my angle is off by 90 degrees?
Code:function degree() return math.rad(math.abs(math.deg(math.atan2(pad:analogX(),pad:analogY()))-180)) end function newx(x, radius, radian) return (x + math.cos(radian)*radius) end function newy(y, radius, radian) return (y + math.sin(radian)*radius) end white = Color.new(255,255,255) blue = Color.new(0,0,255) red = Color.new(255,0,0) aim = -1 pad = Controls.read() x = 240 y = 136 x2 = x y2 = y while not pad:square() do pad = Controls.read() if math.abs(pad:analogX()) > 25 or math.abs(pad:analogY()) > 25 then aim = degree() end if aim ~= -1 then x2 = newx(x, 20, aim) y2 = newy(y, 20, aim) end screen:clear() screen:drawLine(x, y, x2, y2, red) screen:fillRect(x, y, 2, 2, white) screen:fillRect(x2, y2, 2, 2, blue) screen:print(10,10, math.deg(aim), white) screen:flip() end
-
04-30-2007, 02:55 PM #7150QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Thanks for the answer but using your method I get the same time (for offscreen) because of calling image:width() and height() a 100.000 times.
If I compare them to 0 I get a time of zero :)
So basically if i don't have a preset value to which to compare to it doesn't matter which method i use.
-
04-30-2007, 03:04 PM #7151
image:width() or height() are built-in functions and it takes longer to use a function than it takes to access the value of a variable, so try setting up an image table like this:
pic = {}
pic.image = Image.load(image)
pic.width = pic.image:width()
pic.height = pic.image:height()
-
04-30-2007, 03:08 PM #7152QJ Gamer Blue
- Registriert seit
- Apr 2007
- Ort
- Relative
- Beiträge
- 135
- Points
- 3.679
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Yea, I read that discussion.
Thank you all for your help. :)
-
04-30-2007, 03:55 PM #7153QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
your welcome:)
-
04-30-2007, 04:14 PM #7154QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Umm how can i make it so that an image will come up adn ask the viewer to press start to start the program? also would it be possiable to play some sound whil the "press start to confirm image is up"
Code:--Load images into a table Images = { Image.load("images/cycle.jpg"), Image.load("images/background.jpg"), Image.load("images/epic.png"), Image.load("images/test2.jpg"), Image.load("images/work2.jpg"), Image.load("images/need.jpg"), } currentImageToDisplay = 1; while true do screen:clear() pad = Controls.read() if pad:r() and pad ~= oldpad and currentImageToDisplay < table.getn(Images) then currentImageToDisplay = currentImageToDisplay + 1; end if pad:l() and pad ~= oldpad and currentImageToDisplay > 1 then currentImageToDisplay = currentImageToDisplay - 1; end screen:blit(0, 0, Images[currentImageToDisplay]); screen.waitVblankStart() screen.flip() oldpad = pad endGeändert von cruisx (04-30-2007 um 04:33 PM Uhr)
-
04-30-2007, 05:24 PM #7155
make another loop before the one you have for your program. make it display the picture, or text asking the user to press x. in the loop just have
that way, if start is pressed, the current loop is broken, so your program will continue to the rest of your script below it. :tup:Code:while true do screen:clear() screen:blit(0,0,pressStartPic) pad = Controls.read() if pad:start() then break end screen.flip() screen.waitVblankStart() end
For sound, yes it is possible. Just look at the lua wiki for sound functions.
-
04-30-2007, 05:25 PM #7156QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
your smilies not showin
-
04-30-2007, 05:26 PM #7157QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Good to know? ....
Zitat von Urameshi
-
04-30-2007, 05:29 PM #7158
yes i know, i disabled them in text since i posted code, and forgot.

there we go ^^
-
04-30-2007, 05:34 PM #7159QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
-
04-30-2007, 07:36 PM #7160Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I've used these algorithms in my car racing demo when playing around with the gu, and I got the same 90 offset. I could never figure it out so if anyone is really good with trig maybe they can, but I fixed it by subtracting 90 from my angle before calculating the new coordinate.
Zitat von Merick
-
04-30-2007, 08:45 PM #7161QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Upstate, NY USA
- Beiträge
- 121
- Points
- 4.349
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Could anyone tell me what this error means?
"libpng error: Too many IDAT's found"
I thought it meant, there was too many .png files in the folder, but I erased 5 of them & still get the same error...
EDIT: answered my own question... the .png file I was trying to load was too big. It seems to load fine, now that I lowered the size too under 100 kb. :)
-
04-30-2007, 09:05 PM #7162words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
IDAT = image data chunk. IDAT contains all of the image's compressed pixel data. Single IDATs are perfectly fine as long as they contain no more than 2 gb's (i believe its 2) of compressed data, in most images the compressed data is split into several IDAT chunks. This means small IDAT chunks are the most common, particularly in sizes of 8 or 32 kb. The image your trying to load has too many of these IDATs, most likely because your image exporter (photoshop?) compressed it too much for libpng for the PSP to handle the IDATs (?). My advice is to open the PNG in MSPaint (if it doesnt have transparency) and save it as PNG again, but if it does have transparency, use GIMP or someother image editing software to export it as PNG again, at less of a compression.
-= Double Post =-
Thought id comment on this too, as Its not too far back...
Zitat von emericaska8r
Creating multiple infinite loops disrupts a programs 'flow'. You should use a state system to not only have a constant flow, but be able to go back and forth between game states more easily then restarting the script or something.
ex
I believe my syntax is correct there...Code:GameStates = { Intro = 0, Menu = 1, Game = 2 } g_State = GameStates.Intro oldpad = Controls.read() white = Color.new(255,255,255) while true do pad = Controls.read() if g_State == GameStates.Intro then screen:clear() screen:print(0,0,"Game States Example - This is the intro",white) if pad:cross() and pad ~= oldpad then g_State = GameStates.Menu end elseif g_State == GameStates.Menu then screen:print(0,0,"Main Menu",white) screen:print(0,10,"Press X to start game",white) screen:print(0,20,"Press O to go back to intro",white) if pad:cross() and pad ~= oldpad then g_State = GameStates.Game elseif pad:circle() and pad ~= oldpad then g_State = GameStates.Intro end elseif g_State == GameStates.Game then screen:print(0,0,"Game",white) screen:print(0,10,"Press X to go back to main menu",white) if pad:cross() and pad ~= oldpad then g_State = GameStates.Menu end end oldpad = pad screen.waitVblankStart() screen.flip() endGeändert von SG57 (04-30-2007 um 09:17 PM Uhr) Grund: Automerged Doublepost

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
05-01-2007, 12:43 PM #7163
yea, thats a good idea. thanks sg :)
-
05-01-2007, 06:06 PM #7164
Hey guys i have my collision code coded and everything i just have one question.
Spoiler for CODE:
That is my code. What i want to know is how to integrate it so that when my cursor goes over the button it will change the image and then if i hit x on it it will dofile("fb.lua").
Thanks To anyone that helps
Bob Hoil
-
05-01-2007, 06:23 PM #7165QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
if pad:cross() and collision(something,somet hing) then dofile("fb.lua") end
-
05-01-2007, 06:32 PM #7166Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Your code tweaking Hoil, I think it would be good if you wrote this function yourself. A simple loop and a slight modification to your button table is all you need. Put up some code and we can walk you through any logic errors you might run into, but you're never going to learn be asking for ready made code.
My opinion, if someone wants to give and not teach, then by all means. But I think we as a community should support teaching concepts. Give a man a fish and he'll eat for a day, teach a man to fish and he'll eat for life. (as long as there are fish to eat)
-
05-01-2007, 06:33 PM #7167QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Very true. Don't you ever, ever go to evilmana.
Zitat von KleptoOne
-
05-01-2007, 06:39 PM #7168QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Lol evilmana ftl.
-
05-01-2007, 06:51 PM #7169Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Nah, I'm a person of habit, I have my favorites and cycle through them. Some may even consider it borderline OCD, heh. Maybe someday.
-
05-01-2007, 06:54 PM #7170QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Ocd?


LinkBack URL
About LinkBacks
Mit Zitat antworten
rint(325, 26,hour..":" ..min .. " "..ampm, white)

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum