Results 1 to 8 of 8

Thread: lua?????????

                  
   
  1. #1

    Question lua?????????

    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

  2. #2
    PSP Coder benh's Avatar
    Join Date
    Mar 2006
    Location
    linclonshire, England
    Posts
    362
    Rep Power
    71

    Default

    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
    Benh = Coder, main language C other language LUA

    Check out my first C app Super - flasher here

    visit my dev site where you can download all of my coding projects - http://benh-pspdev.bravehost.com/



    Please visit my site www.pspfanatic.bravehost.com
    and join the forums

  3. #3
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    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.

  4. #4
    DCEmu Rookie
    Join Date
    Jun 2006
    Posts
    125
    Rep Power
    70

    Default

    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

  5. #5
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    Quote Originally Posted by xiringu
    I think you are looking for this:

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

  6. #6

    Default

    thx try it out know

  7. #7

    Default

    i used it in a example but it doesnt work:

    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

  8. #8
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •