 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
fade
Joined: 01 Oct 2005 Posts: 2
|
Posted: Sat Oct 01, 2005 4:55 am Post subject: Lua Newbie Question |
|
|
I'm pretty new to lua and i've enjoyed messing around with it so far, but i need some seasoned help..
My question...I've written a simple test script based off the smiley animation tutorial. You can move the smiley about the screen in the script and play a sound when the cross button is pressed. This is easy enough, but the problem is that i've noticed that if you keep your finger on the button it plays the sound over and over again continously, really quickly, which sounds horrible. Whereas i only want it to play the sound once, even if the button is held down. And also after letting the button back up, work again only once with each button press. I'd also like to do this with some frames of animation, have lua display maybe 4 or 5 frames of animation for a sprite upon pressing a button, but NOT repeat them if the button is held down. Does lua have a timer maybe to let it play for perhaps half a second and then stop? Is a timer even the best method to do this?
My script is below, any help is much appreciated. :)
| Code: | -- Activate USB Mode
System.usbDiskModeActivate()
-- load sounds
smileyfiresound = Sound.load("DATA/SOUNDS/blam.wav")
-- Load images
smiley = Image.load("DATA/IMAGES/smiley.png")
-- Load Backgrounds
background = Image.load("DATA/BACKGROUNDS/background.png")
-- Set Variables
fire_pressed = false
smiley_x_pos = 200
smiley_y_pos = 100
-- Set Functions
function fire()
smileyfiresound:play()
end
-- Set starting X/Y positions
x = smiley_x_pos
y = smiley_y_pos
while true do
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen:blit(x, y, smiley)
screen.waitVblankStart()
screen.flip()
-- CONTROLS
pad = Controls.read()
if pad:up() then
y = y - 5
if y < -4 then
y = -4
end
end
if pad:down() then
y = y + 5
if y > 230 then
y = 230
end
end
if pad:left() then
x = x - 5
if x < -4 then
x = -4
end
end
if pad:right() then
x = x + 5
if x > 440 then
x = 440
end
end
-- END OF CONTROLS
-- FIRE
if pad:cross() then
fire();
end
if pad:start() then -- press start to restart
break
end
end |
|
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Oct 01, 2005 5:32 am Post subject: |
|
|
add a variable where you count the animation frames (from 0 to 5) when its 5 set it back to zero
further you may add a boolean variable which tells you if you pressed the button (if pressed another variable will be counted up)
note that psp uses 60fps (so if the variable reaches 60, one second passed by....)
the rest is straight forward
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
fade
Joined: 01 Oct 2005 Posts: 2
|
Posted: Sat Oct 01, 2005 6:00 am Post subject: |
|
|
| Thanks a lot |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|