DSLua Community
Welcome, Guest. Please login or register.
May 18, 2012, 09:20:19 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Need Help?  |  Touch point on screen to make sound? « previous next »
Pages: [1]
Author Topic: Touch point on screen to make sound?  (Read 1932 times)
brennan
Waxing Crescent
**
Posts: 41


WWW
« on: July 19, 2006, 04:34:50 PM »

Okay, I just started to create a soundboard of sorts using DSlua. What I want to do is have a button at a certain point on the screen, and when you touch that button, it plays a sound. Would it be similar to
Code:
while true do
if Pads.A() then
...

?

If so, how do I tell it to play the sound when you press a variable on the screen (instead of the A button), and how do I specify the location?

Thanks in advance.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #1 on: July 19, 2006, 06:22:31 PM »

This would be it:
Code:
while true do
if Pads.A() then
Somesound = Sound.LoadRaw( "Somesound.raw" )
Somesound:Play()
end
end

That would be a simple loop. Make sure that you free the sound at some point. Maybe like this:

Code:
FREEMUSIC = 1
while true do
if Pads.A() then
Somesound = Sound.LoadRaw( "Somesound.raw" )
Somesound:Play()
FREEMUSIC = 2
end
if Pads.Start() then
if FREEMUSIC == 2 then
Somesound:Free()
end
break
end
end

Try that code, and replace somesound.raw with your raw sound file. The End!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
brennan
Waxing Crescent
**
Posts: 41


WWW
« Reply #2 on: July 19, 2006, 10:26:47 PM »

Good to know. But... I want to have buttons on the touchscreen, and when you touch them, it outputs sound.

How would I specify the point on the touchscreen that plays the sound? Let's say I wanted a button dead center, and it would play sound.raw, what would be the code for that?

Sorry if I was unclear in my first post  Embarrassed.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #3 on: July 20, 2006, 08:11:36 AM »

I made my own little math algorithm (spelling issues, I know) for that. Here's how:

1. First, find the X and Y (horiz and vert) of the sprite you are centering.

2. Divide the X of the button in half, and in your head, call that NX. Here:

XCenter = 128 - NX

XCenter is the X you should put the sprite at to PERFECTLY center it.

3. Now for the Y. Divide the sprite's Y value in half and call it NY in your head. Then:

YCenter = 96 - NY

YCenter is then the Y value you need to use for perfect centering.

4. Now that the image is perfectly centered, let's handle the touching. Example:

Code:
FREESOUND = 1
while true do
if Stylus.Down() then
if Stylus.X() > 111 then
if Stylus.X() < 145 then
if Stylus.Y() > 79 then
if Stylus.Y() < 113 then
Somesound = Sound.LoadRaw( "YourRawHere.raw" )
Somesound:Play()
FREESOUND = 2
end
end
end
end
end
if Pads.Start() then
if FREESOUND == 2 then
Somesound:Free()
end
break
end
end

That would be what it would look like of the sprite was a 32*32 sprite. You have to make the values want greater than one less than where it starts, and less than where it ends + 1. But 32*32 is a reasonable size, so get a 32*32 button if you wanna save trouble.

There you go!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
brennan
Waxing Crescent
**
Posts: 41


WWW
« Reply #4 on: July 20, 2006, 03:12:34 PM »

Thanks a lot.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #5 on: July 20, 2006, 06:53:54 PM »

Yer welcome. I know how long it takes to learn this stuff *coughwithoutproperdocumentationscough*, so I am here to help.
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Pages: [1]
« previous next »
    Jump to: