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.

DarkBASIC Discussion / alternative for sprites menu system

Author
Message
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 27th Jan 2003 21:40
hi

I'm still busy with my 3d card game... I have to make a little in-game menu. I didn't try to do it in 3d because that would be a bit too complex I guess, so I tried to make it using sprites.
The menu contains 10 buttons, containing 3 sprites for each button (a normal one, a highlighted one - for when the mouse is on top of the button -, and a grey one (for when the function is disabled)).
Problem: it's way tooo slow, I guess I only have 5 fps in it...

The menu system should appear on top of the 3d camera view. I was testing the menu system without 3d under it and it was that slow...
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Jan 2003 21:48
Have you got some (small) example code so we can see what you are doing?
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 28th Jan 2003 00:36
Ok, here it comes...
Sorry, it isn't small.

In fact, it worked properly until I used a sprite command in my main loop.



IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Jan 2003 02:55
Obviously I don't have the media, so can't run it, but I do have an observation.

You are loading your .bmp's into bitmaps then using GET IMAGE() to convert them to images. Use LOAD IMAGE() instead.

I can't see any reason for things to go slowly inside your loop though.

If you want to email me the media, I'll have another look in the morning.
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 28th Jan 2003 18:22
oh I didn't know there was a command like LOAD IMAGE() It's quite usefull to know this...

I think sprites moving in real-time are always slow (there's a sprite positioned at the mouse's coordinates, I wanted to use this to perform sprite collision with the buttons).

But I changed the way it is detected that the mouse is over a button, and I it's a lot faster this way:



So a variable with the number of the button under the mouse is returned.

xmen
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location:
Posted: 28th Jan 2003 22:41
Try this out hope it help



`set display mode 800,600,16
`set window on

`..................................
`BY XMEN
`..................................

dim menuclick(1)
dim menu$(10)

menu$(1)="wachten"
menu$(2)="pas"
menu$(3)="vragen"
menu$(4)="meegaan"
menu$(5)="alleen"
menu$(6)="ambondance"
menu$(7)="soloslim"
menu$(8)="kleinemiserie"
menu$(9)="grotemiserie"
menu$(10)="miserieoptafel"
backdrop off
sync on

do
text 1,1,"Press mouse button 1 for menu"
mc=mouseclick()
if mc=1 then mc=0:sleep 100:menu(120,0,10):sleep 100
if menuclick(1)>0 then text 120,120,"you click menu "+str$( menuclick(1))
sync
loop


function menu(x,y,l)

set text font "times new roman"

set text size 15
dim menux(l)
dim menuy(l)
dim mwidth(l)
dim mheight(l)
dim ops$(l)
dim menuops(l)
ex=0

for a=1 to l
ops$(a)=menu$(a)
next a
tw2=0:tw3=0:tw=0

for a=1 to l
for b=1 to 2
tw2=text width(ops$(a))
if tw2>tw3 then tw3=tw2
next a
next b

tw=tw3
mposy=y+16
for pos=1 to l
menux(pos)=x
menuy(pos)=y+pos*16
mwidth(pos)=x+tw+5
mheight(pos)=16+y+pos*16
menuops(pos)=pos

next pos
oxm=mousex()
oym=mousey()

repeat
xm=mousex()
ym=mousey()

for pos=1 to l

ink rgb(210,210,160),1

if image exist(1000+pos) then box x,y+pos*16,x+tw+5+50,18+y+pos*16
box x,y+pos*16,x+tw+5,18+y+pos*16
ink rgb(165,165,125),1
box x+1,y+1+pos*16,x+tw+4,17+y+pos*16
ink rgb(10,10,10),1
text x+3,y+pos*16,ops$(pos)


if mousex()>menux(pos) and mousex()<mwidth(pos) and mousey()>menuy(pos) and mousey()<mheight(pos)

ink rgb(190,190,140),1
box x+2,y+2+pos*16,x+tw+3,16+y+pos*16
ink rgb(255,255,255),0
text x+3,y+pos*16,ops$(pos)

endif

if mouseclick()=1 and mousex()<>oxm and mousey()<mposy
menuclick(1)=0
backdrop on
ex=1
endif

if mouseclick()=1 and mousex()>menux(pos) and mousex()<mwidth(pos) and mousey()>menuy(pos) and mousey()<mheight(pos)
ink rgb(190,190,140),1

box x+2,y+2+pos*16,x+tw+3,16+y+pos*16

ink rgb(250,250,250),1
text x+3,y+pos*16,ops$(pos)
menuclick(1)=menuops(pos)
ex=1
endif

if mouseclick()=1 and mousey()>mheight(pos)
menuclick(1)=0
ex=1
endif

next pos


sync
until ex=1
backdrop on

undim menux(l)
undim menuy(l)
undim mwidth(l)
undim mheight(l)
undim ops$(20)
undim menuops(l)

endfunction menuclick(1)
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 28th Jan 2003 23:18
nice code snippet, and it's fast too (way faster than using sprites)!

but I already made another (temporary) menu: just a line at the bottom of the screen which says something like:
1=wachten 2=pas 3=vragen 4=meegaan ...

I'll first continue with the rest of my program (a card game) and if I have something that is playable I'll start making some parts better. If I use some of your code (or if I use it as a source of inspiration), I'll put your name in the credits

Login to post a reply

Server time is: 2024-05-05 00:00:53
Your offset time is: 2024-05-05 00:00:53