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 / Simple Character Selection/Loop Problem

Author
Message
Gilden
20
Years of Service
User Offline
Joined: 10th Aug 2004
Location:
Posted: 25th Mar 2005 08:31
I use dark Basic Pro and have a looping problem. I have a character selection screen. There are character portraits and two arrows facing left and right beneath them. I want users to be able to select their portrait. When clicking the left arrow it shows a new portrait. They can click it again and it shows another new portrait. When clicking the right arrow it goes back to the previous portraits.

It seems like such a simple thing to do but I've already taken a month on my own trying to do it with loops and I cannot.
Please help if you know how to do it with loops or another way.

Also When I click the arrow I want a clicking sound to play. I have been able to accomplish that but when I hold the mouse button down it repeats the sound indefinatly when I want the sound to only play once. Help with either problems will be appriciative.

Thanks for your help!
Soy Cocktail
20
Years of Service
User Offline
Joined: 23rd Dec 2003
Location:
Posted: 25th Mar 2005 10:28
This might sound simple, but a nice interface can be very complex. Most likely you will need to use variables. I am going to assume that you already know what those are, if you dont just post. You will need a variable for which portrait it is going to display. This is fairly simple. When you click the left arrow decrease that variable. When you click the right increase that variable. There are several ways to do buttons, there isin't any really right or wrong way to do it as long as it works. The method I use for standard buttons is a function. By a standard button I mean one that has a default position ie mouse isint over it, a hover position ie mouse is over it, and a down position ie you clicked the button. It also acts like regular buttons you would see in windows, that is that you can click it and it won't do anything untill you release the mouse button. If you drag the mouse pointer off the button it will go back to the default position unless you move the mouse back then it goes back to the down position. This is fairly complicated like I said. You will probably want to start off with a simple button, if you want the more advanced version like I am talking about just post. One of the easiest buttons to make is the regular square button. This method uses the mouses x and y position. This works like the following:
If mousex()>10 and mousex()<20
if mousey()>10 and mousey()<20
`display hover image
if mouseclick()=1
decrease portraitnum#
endif
endif
endif
This will create a button at the top left of the screen it is a 10x10 box that starts a 10x, and 10y. This button is invisable unless you tell it to draw a picture there. The picture will no affect the button. Square boxes are simple quick and effictive.

I have heard of methods using sprites for buttons and having a custom curser tat is a sprite for the mouse cursor. All you have to do is check for sprite collision this way. I assume it works something like:
`sprite 1 is the mouse cursor
`sprite 2 is the button (left arrow)
do
sprite 1,mousex(),mousey(),1
if sprite collision(1,2)=1 and mouseclick()=1
dec portraitnum#
endif
loop

What this does is it positions the cursor at the mouses position and checks to see if the two sprites are overlapping and the mouse is clicked then it will decrease the portrait number variable. You would need to hide the mouse and position the arrow sprite.

I would just use the sprites to do this, as its an easy method.
You will need to load your images first.
load image "cursor.bmp",1
load image "leftarrow.bmp",2
`load all of your protraits here starting with portriat number 1 as image 100
hide mouse
sync on :sync rate 60
portrait#=1
totalportraits#=10 `change this value to however many sprites there are.
do
cls
paste image portrait#+99,300,100
sprite 2,300,400,2
sprite 1,mousex(),mousey(),1
if sprite collision(1,2)=1 and mouseclick()=1
dec portrait#
if portrait#=0 then portrait#=totalportraits#
endif
sync
loop

I havent tried the code, but it compiles without any errors.

When life hands you lemons go buy some oranges to make orange juice, and stop expecting everything to be given to you.
Gilden
20
Years of Service
User Offline
Joined: 10th Aug 2004
Location:
Posted: 25th Mar 2005 13:01
Thanks for your reply. Sorry I was not able to reply until now. I have already created a mouse that shows clearly on the screen using this code:

`places mouse pointer & it moves
sprite g_MOUSE, mousex(), mousey(), g_MOUSE


Then I've declared image sprite variables for my artwork using globals:

global g_ARROWRIGHT as integer : g_ARROWRIGHT = 2
global g_ARROWRIGHT2 as integer : g_ARROWRIGHT2 = 3
global g_ARROWLEFT as integer : g_ARROWLEFT = 4
global g_ARROWLEFT2 as integer : g_ARROWLEFT2 = 5
global g_MOUSE as integer : g_MOUSE = 6
global g_FACE1 as integer : g_FACE1 = 7
global g_FACE2 as integer : g_FACE2 = 8
global g_FACE3 as integer : g_FACE3 = 9


Then I have loaded my images, portraits, arrow, mouse, image and assigned them the variable names above. g_MOUSE, g_FACE. So I have gotten this far already. If you understand the way I've done this so far.

Next I will explain how the program runs and the difficulty I face then give you the code I am using. It actually may be helpful to other users:
* I load the program
* My mouse works fine and I see the character face and arrows to push and change them to different faces. When I move my mouse over the arrow it highlights then I click the mouse and I hear a clicking sound.
* This is where I run into trouble. I can get the portrait to change to one other picture using a if endif loop. But then cannot get it to change to another picture and back again.
* This is my code:

if (sprite hit(g_MOUSE,g_ARROWLEFT,)=1)
hide sprite g_ARROWLEFT
show sprite g_ARROWLEFT2
If sprite exist(g_ARROWLEFT2) and sprite exist(g_FACE1) and mouseclick()=1
hide sprite g_FACE1
show sprite g_FACE2
play sound 2
endif
else
show sprite g_ARROWLEFT

endif


I liked your idea of when I would click the left arrow it decrease that variable. When I click the right arrow it increases that variable. I don't know how to do that.

For the most part,everything works. Except for my clicking sounds repeats when I hold down the mouse button and of course this loop is not working for changing my pictures.

I will try and work with what you've given me for now thanks.

Gilden
Gilden
20
Years of Service
User Offline
Joined: 10th Aug 2004
Location:
Posted: 26th Mar 2005 02:37
I'm using a new code and its working better. I can get the pictures to change clicking the left and right arrow. I'm using the dec and the inc code. I can't seem to stop the code from inc or dec when it reaches a certain number. It keeps going, says that sprite does not exist then exits the program. This is my code:

_handle_mouse:
`place mouse pointer & it moves
sprite g_MOUSE, mousex(), mousey(), g_MOUSE
hide sprite g_ARROWLEFT2
hide sprite g_ARROWRIGHT2
`****************************************************************
`check for collision and mouse click
`sprite collision

if (sprite hit(g_MOUSE,g_ARROWRIGHT,)=1)
hide sprite g_ARROWRIGHT
show sprite g_ARROWRIGHT2
if (sprite hit(g_MOUSE,g_ARROWRIGHT,)=1 and mouseclick()=1)
hide sprite g_FACE1
inc g_FACE1
show sprite g_FACE1
wait 200
play sound 2
endif
else
show sprite g_ARROWRIGHT
endif

if (sprite hit(g_MOUSE,g_ARROWLEFT,)=1)
hide sprite g_ARROWLEFT
show sprite g_ARROWLEFT2
if (sprite hit(g_MOUSE,g_ARROWLEFT,)=1 and mouseclick()=1)
hide sprite g_FACE1
dec g_FACE1,1
show sprite g_FACE1
wait 200
play sound 2
endif
else
show sprite g_ARROWLEFT
endif

return



Please anyone help me if you can I AM STUCK!

Gilden

Login to post a reply

Server time is: 2024-09-23 15:34:26
Your offset time is: 2024-09-23 15:34:26