Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Menu Troubles

Author
Message
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 22nd Jul 2006 18:35
What I want here is when the mouse hovers over a sprite, for the sprite to "change" to a different sprite. However, nothing happens when I click OR hover. A small section of the code is below.



erm

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 22nd Jul 2006 18:43
There is a very small chance that mousex will equal exactly 100 and mousey will equal exactly 500. You probably want to do.



also, instead of having 2 different sprites for this you could use set sprite image. Your whole code would then be something like this-



assuming that you are using images 1 and 2 (Change the parameters in the set sprite image if you are not).

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 22nd Jul 2006 18:49 Edited at: 22nd Jul 2006 19:02
Hmm. That doesn't seem to work. And the sound only plays when the mouse moves away from the sprite. The image also doesn't change at all.

EDIT: Wait, I figured it out. I forgot to add a sync before the loop.

Thanks for your help!

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 22nd Jul 2006 19:32
Sorry about double posting but...

Now the sounds will not play when the cursor hovers over the sprite. I know it has something to do with the values in the mousex()> thing, but I'm not sure.




erm

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 22nd Jul 2006 20:58
In your second if test you use sprite width(1) and sprite height(1) when you should have a 2 within the parenthesis.

Also, you may want to check to see if the sound is already playing.

That is all that I could spot.


The code with my suggestions-


Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 22nd Jul 2006 23:54
Ok, I tried that but the sound plays constantly unless the mouse is hovering over the sprite.

erm

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 23rd Jul 2006 02:09
create a 1x1 pixel sprite and position it at the mouse position, Then use the SpriteHit command to check for collision with the menu sprites. This is the simplest method.

Check this thread for the example I posted http://forum.thegamecreators.com/?m=forum_view&t=84188&b=7

Cheers,

Cloggy
ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 23rd Jul 2006 02:53
Aw, cloggy, that's the hard way.

Jrock, as I understand it, you don't want the sound to play when the mouse is over the buttons?



Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 23rd Jul 2006 03:46
No, I do want it to play when the mouse is over the buttons. With that other code by Daemon, it only played when the mouse was "leaving" the sprite.

erm

ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 23rd Jul 2006 04:33
Okay



Is that what you mean?

Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 23rd Jul 2006 09:31
Quote: "Aw, cloggy, that's the hard way."






is harder than



?

I don't really see it myself, my method doesn't require you to make changes every time you move/add/remove menu items.

It's seems the simplest solution to me .

Cheers,

Cloggy
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 23rd Jul 2006 18:16
It still does not play any sounds, its kind of strange.

erm

ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 23rd Jul 2006 19:44
Hmm Jrock, I get the idea something else in your code is messing things up.

Cloggy: Not the easier way, exactly, but much more organized and mathematical.

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 23rd Jul 2006 23:12 Edited at: 24th Jul 2006 18:33
I'll recheck it.

EDIT: Wow thats werid. Only 1 button works at a time, if I code it so all of them play the sound they don't work.

EDIT: Maybe its a bug??

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 24th Jul 2006 22:04
Sorry guys I have to bump this

erm

ThinkDigital
19
Years of Service
User Offline
Joined: 18th Aug 2005
Location: A galaxy far, far away...
Posted: 24th Jul 2006 22:12 Edited at: 24th Jul 2006 22:13
Okay, so what's the story with that "b" variable you keep messing around with in the code you gave us? What's it do?

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 24th Jul 2006 22:26
This is what it does-


It seems that if I set the same sound commands for each one, then it doesn't work. If I set the sound command for just one, it works on that particular sprite.

erm

Cerafem
18
Years of Service
User Offline
Joined: 29th Jun 2006
Location: here
Posted: 28th Jul 2006 06:08
try making it just change "a", then later make it change sprite and play sound.

---

-Agent Toaster Productions
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 28th Jul 2006 19:45
I tried that, it does not help because you are just delaying the events.

erm

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 29th Jul 2006 07:01
I may have a solution to your problem.



This code was adapted from DB Classic example program #10 for recording
sounds. I boiled it down to the essentials and added some parameters to
the newly renamed function.

All the parameters for the function should be self-explanatory. The values
in the code are for place holders and demonstration purposes. You will have
to fill them in with your own numbers.
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 29th Jul 2006 08:51
I'm sorry, but this is all wrong!

So, for your need of help, use THIS!


How you use that function is by saying hovering#=IsMouseOverSprite(examplesprite#)
then if you want to see if it's being clicked is by saying,
if mouseclick()=1
if IsMouseOverSprite(examplesprite#)=1 then clicked#=1
endif

See? It works. You may need to respell some text though, but the overall concept works.

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 29th Jul 2006 21:10
To DB user 2006+: I think you missed some things with your example. Jrock
wants the image to change for each sprite when the mouse pointer is over
them. He/she also wants a sound to play when this happens.

I don't know how you can say this is all wrong. There are many ways you
could write the code. I know may example works! My function not only handles
the mouse, but it also handles sprite placement, image changes, and
sound effects.

Besides, your code is flawed anyways. Unless the variable RES is an array or
defined as global (DBPro), the function is not returning a value that can be
checked in an IF/THEN statement. Also, why would you make use of real numbers
for variables here? Mouse movement and sprite positioning is all done in pixels
where integers would suit. Integers take up less memory and require less time
to process by the computer. Another thing, why use four IF/THEN statements to
check the mouse position against the sprite boundries? Two will work here...

Actually now that I think of it, one IF/THEN would work just as well.

Here's my code modified for one IF/THEN statement:


I know you're probably excited about helping someone here. I think
next time you should try reading all of the thread before you post
something. Don't just blurt out stuff without knowing what's going
on first.

To Jrock: If you use my code and have any problems with it, just let
me know. I'll try an help. That's why these forums are here.
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 30th Jul 2006 00:00 Edited at: 30th Jul 2006 00:03
Ok, let me check your code out.
This could be hard to adapt to my code, I already have a loop and such.
I'll try this out tommorow, I have to go for now.

erm

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 30th Jul 2006 19:11 Edited at: 30th Jul 2006 20:16
Implementing my function shouldn't pose a problem in your code. It's designed
to work without interrupting any other loop processes. So, if you have an animation
or something happening in the background for your game menu, just place the function
call(s) at the end of the loop.

Example:


The only thing that may cause confusion is the function parameters.
You will have to load your media to be used with the function first.
Below is a detailed list of what the parameters mean to the function.

Parameters:

x,y screen position for current sprite (icon).

IconNumber is the current sprite used during the function call.

IconImage1 is the initial image displayed before the mouse pointer is over the sprite.

IconImage2 is the active image when the mouse pointer is over the sprite.

SFX is the current sound used for the sprite when the pointer is over the sprite.

The function will return the appropriate value (0 or 1) based on user
selection with or without a mouse click.

You could also adapt the function to use pasted images instead of sprites.
The only advantage to using sprites is having the ability to flip or mirror
them in real time as well as collision.

<EDIT>

Because the function uses sprites, you may have to delete the sprite(s)
used for the icons upon exiting the game menu loop. If you use pasted
images, this will not be an issue.

To use pasted images just change the code to:


This will also eliminate one of the parameters in the function. You
may have to change the sprite number in the function to something not
used in your game. This is used to get the current size of the icon.
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 31st Jul 2006 20:14 Edited at: 31st Jul 2006 22:07
Ok I will make the changes and try to implement it in. I'll get back to you soon (its been a very, very, very, busy week).

Another thing, I am using Subroutines, so I guess I would just replace the goto statement with gosub?

And one more thing, if I am using multiple sprites... what would I do?

Would it be...


like that?

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 2nd Aug 2006 18:29
Sorry I have to bump this again.

Oooo that didn't go so well with my code, I'll try again.

erm

Acolyte Entertainment
19
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 2nd Aug 2006 20:24 Edited at: 2nd Aug 2006 20:25
Jrock. as you know iv been making a menu.
i decided not too use sprites just images . here is a snippet of my code. you can mod it a bit too your liking.



this code is built for 1600,1200 res. in the
its saying if you move the mouse over the button it will replace the image with a different one (the lit up one) else it will keep the one there.

please go too my menu thread and look at the tutorial i wrote for sixtry squares. that should help

yw,
-snow
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 2nd Aug 2006 21:21 Edited at: 2nd Aug 2006 21:28
Thanks snowfall. Ya, I guess just using images would be easier.

Der, where is your menu thread?



EDIT:I'll run a test with just images, and see what happens.

EDIT2: I think I would rather just leave it as sprites, because the only thing that isnt working is the sounds.

erm

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 2nd Aug 2006 23:25 Edited at: 2nd Aug 2006 23:48
Sorry for taking so long to post back...

If you are still using my function:

Answer to question #1: Yes, you can use gosubs instead of gotos. Just watch how many
subroutines you execute at one time throughout your code. This may cause a stack overflow
error if you use a lot of them.

Answer to question #2: You don't have to make any changes to the function to use multiple
sprites. The IconNumber parameter passed to the function during the call in the main loop
tells the function what sprite to use at that time. If you use a 1 for this parameter, then
sprite #1 is used. If you use a 2, then sprite #2 is used. If you use a 3, then sprite #3 is
used, and so on. My example code used 3 sprites. One for each icon with 3 IF/THEN's..

Make sure the appropriate media is loaded and you've passed the correct sprite, image, and
sound numbers to the function.

Function call parameter syntax (Use inside of an IF/Then statement):

IF MakeIcon(x,y,IconNumber,IconImage1,IconImage2,SFX)>0 Then Gosub whatever

x,y - screen position of sprite

IconNumber - sprite number

IconImage1 - first sprite image number

IconImage2 - second sprite image (alternate) number

SFX - sound number
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 3rd Aug 2006 00:03
I have a question for you. Do you want the sound to play when you mouseclick()
over the sprite or just when the pointer is resting over it?

It will just repeatedly play resting over it currently in my function.
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 3rd Aug 2006 00:13
I just want it to play once when the user hovers over it, and a different sound when the user clicks it.

I am making a different function to custom fit what I need, but your function is very helpful. However, I might still use it.

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 3rd Aug 2006 00:42 Edited at: 3rd Aug 2006 00:53
I think this deserves a double post

I just added this code...


...and it worked.

I basically loaded the same sound 3 times and classified it in order as 1,2,and 3.

erm

D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 3rd Aug 2006 00:56 Edited at: 3rd Aug 2006 01:07
Okay, give it a try and see what you can come up with.

However, I did make a few changes to the code to provide you with a sound once
mouseclick()=1 over the sprite. I would have to make some more changes to the
the code in order to satisfy all your needs in the sound department.

Unfortunately, I won't be able to do this until next week. I will be going out of
town.

My current code revision:


<Edit>
Oops! You posted before me. That's great that you go it to work!

Depending on how YOUR code is setup, you can either pass the same sound
number for each call of the function in the If/Then statements or you can
use CLONE sound to make a copy of the sound instead of loading it 3 times.
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 3rd Aug 2006 02:50
Ah, I'll probably just clone it I guess.

Thanks for all your help D Ogre!

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 3rd Aug 2006 22:35 Edited at: 4th Aug 2006 03:20
Gargh... Now when I want to use a sprite for the background transparency image, (The Video goes behind it), upon compiling DBpro says "Runtime Error 302: Sprite does not exist at line XXX"

BUT IT DOES EXIST! I have all the actions relating to the sprite after it was created, any idea(s)?

Code:


UPDATE: Fixed it, really strange... I had to delete the REM statement.

erm

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 4th Aug 2006 15:16
You've run into a concatenation problem!

... is a concatenation marker in some installations of DB - you can change it in the editor.

The compiler read it as


Hope this explanation helps!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 4th Aug 2006 17:41
Ah, I see now. Somewhat strange, no?

erm

Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 5th Aug 2006 19:43 Edited at: 5th Aug 2006 19:45
Grrrr... it still whines about the sprite "not existing".

(This happens like 5 seconds into the program)

Maybe I should make it so the loop ends before the "newgame" and "options" and just use seperate loops for them.

Jrock is pronouned Jay-Rock
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 6th Aug 2006 18:14
Bump* Maybe I am having more of those concatenation errors?

Jrock is pronouned Jay-Rock
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 6th Aug 2006 19:09
Possibly...Post some code, and let us debug it!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Jrock
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Riven
Posted: 10th Aug 2006 18:54
Der, I fixed it again.

And now for another question, is it possible to set an animation's priority? Like the SET SPRITE PRIORITY?

Jrock is pronouned Jay-Rock
D Ogre
21
Years of Service
User Offline
Joined: 19th Nov 2003
Location:
Posted: 10th Aug 2006 23:42 Edited at: 11th Aug 2006 00:00
The frames used for the animation sequence must be determined by you for
any given action or re-action event. So, no there isn't any one command that
will automatically prioritize the frames used for animating a sprite. You can
use variables for that.

If you want to know how to control an animated sprite or textured plain,
here's a link: http://forum.thegamecreators.com/?m=forum_view&t=82482&b=7

Login to post a reply

Server time is: 2024-11-26 13:25:17
Your offset time is: 2024-11-26 13:25:17