PDA

View Full Version : lua?????????



one winged angel
August 13th, 2006, 16:16
i have question about lua on psp

i want to print a image to the screen if no button is pressed not always just if no button is pressed

kind like this:
if pad:nil() then
screen:blit(............)

nil is if no button is pressed but that doesnt work

benh
August 13th, 2006, 16:23
if you want to display an image without pressing a button you just do EG

screen:clear()
background = Image.load("background.png")

and it should display the image and of course blit it at the bottom

yaustar
August 13th, 2006, 16:32
You have to set a flag when a button is pressed


IsButtonPressed = false

if pad:cross() then
IsButtonPressed = true
-- Do whatever happens when a button is pressed
end

if pad:square() then
IsButtonPressed = true
-- Do whatever happens when a button is pressed
end

-- etc
if not IsButtonPressed then
screen:blit(............)
end


nil() is not a function of the object pad. That is why pad:nil() doesn't work.

xiringu
August 13th, 2006, 17:07
I think you are looking for this:

"Controls.read():buttons()" returns 0 if no button pressed


--begin example

lastpad = nil;
pic = Image.load("a.png");

while (not Controls.read():start()) do
pad = Controls.read();

--shows the pic if no button pressed
--and a black screen if pressed
if (pad:buttons() == 0) then
screen:blit(0,0,pic);
else
screen:clear(Color.new(0,0,0))
end

screen.waitVblankStart();
screen.flip();
lastpad = pad;
end

--end example

yaustar
August 13th, 2006, 18:02
I think you are looking for this:

"Controls.read():buttons()" returns 0 if no button pressed
Nice, didn't know about that function.

one winged angel
August 14th, 2006, 12:44
thx try it out know

one winged angel
August 15th, 2006, 05:07
i used it in a example but it doesnt work::confused:

lastpad = nil;
player = Image.load("stand.png");
swordattack= Image.load("swordattackright.png");

while (not Controls.read():start()) do
pad = Controls.read();

if (pad:buttons() == 0) then
screen:blit(0,0,player);
else
screen:clear(Color.new(0,0,0))
end

if pad:cross() then
screen:blit(0,0,swordattack)
end

screen.waitVblankStart();
screen.flip();
lastpad = pad;
end

when i start it and puss cross swordattack will be blit and player will be gone but when i dont push cross swordattack stays on the screen and player.png and swordattackright.png overlaps each other. i thought maybe it works this way(didnt work swordattack wont be even blit when i push cross):

if (pad:buttons() == 0) then
screen:blit(0,0,player);
swordattack:clear()
else
screen:clear(Color.new(0,0,0))
end

yaustar
August 15th, 2006, 11:13
This would be better in this case:

player = Image.load("stand.png");
swordattack= Image.load("swordattackright.png");

while (not Controls.read():start()) do
pad = Controls.read();

screen:clear();

if pad:cross() then
screen:blit(0,0,swordattack);
else
screen:blit(0,0,player);
end

screen.waitVblankStart();
screen.flip();
end

or

player = Image.load("stand.png");
swordattack= Image.load("swordattackright.png");

while (not Controls.read():start()) do
pad = Controls.read();

screen:clear();

if pad:cross() then
screen:blit(0,0,swordattack);
end

if pad:buttons() == nil then
screen:blit(0,0,player);
end

screen.waitVblankStart();
screen.flip();
end