Here is another menu snippet
Rem Project: Menu
Rem Created: 30/03/2005 08:55:30
Rem ***** Main Source File *****
#constant cameraFOV 61.9621391296
#constant VECCAMERA 1
#constant VECOBJECT 2
set display mode 1024,768,32:autocam off:sync on:backdrop on:color backdrop 0
dist#=(screen height()/2)/tan(cameraFOV/2)
r1=make vector3(VECCAMERA)
r1=make vector3(VECOBJECT)
position mouse 0,0
do
text 0,0,"You Selected Item "+str$(Display_Menu(0,0,0))
sync
while mouseclick()=0
endwhile
while mouseclick()<>0
endwhile
wait 200
loop
Function Display_Menu(MenuX,MenuY,MenuZ)
rem set up menu parameters
ItemHeight=71
ItemWidth=500
rem space between top of one item and top of next
Spacing=ItemHeight+15
NumberOfItems=7
BaseObj=1
rem used to center menu
ItemPos#=(NumberOfItems/2.0)+.5
rem I have created this image to texture the menu item as
rem the color object code doesn't word
cls rgb(184,0,0)
get image 1,0,0,ItemHeight,ItemWidth,1
position camera MenuX,MenuY,MenuZ
point camera MenuX,menuY,MenuZ+1
rem create your menu items
for i=1 to NumberOfItems
Make object plain baseobj+i-1,ItemWidth,ItemHeight
texture object baseobj+i-1,1
PositionHudObject(BaseObj+i-1,MenuX,MenuY+((i-ItemPos#)*Spacing),MenuZ)
next i
rem The following lines are an example, you could paste sprites instead of using text
ink rgb(255,255,255),rgb(255,255,255)
set text size 36
set text transparent
do
for i=1 to NumberOfItems
PositionHudObject(BaseObj+i-1,MenuX,MenuY+((i-ItemPos#)*Spacing),MenuZ)
rem Display your menu text/sprite here
center text object screen x(BaseObj+i-1),object screen y(BaseObj+i-1)-text height("M")/2,"Menu Item " +str$(i)
next i
rem This code highlights the menu item
Highlight=pick object(mousex(),mousey(),BaseObj,BaseObj+NumberOfItems)
if Highlight>0
rem Get them current camera vector. There is a command to do this is easier to code
pick screen object screen x(Highlight),object screen y(Highlight),1
rem transfer the camera vector into a new vector for doing the calculations
set vector3 VECCAMERA,get pick vector x(),get pick vector y(),get pick vector z()
rem set up 2nd vector with position of menu item
set vector3 VECOBJECT,object position x(Highlight),object position y(Highlight),object position z(Highlight)
rem move the menu item towards the camera.
multiply vector3 VECCAMERA,-80
add vector3 VECOBJECT,VECCAMERA,VECOBJECT
position object Highlight,x vector3(2),y vector3(2),z vector3(2)
rem return the selected item number
if mouseclick()=1
SelItem=Highlight-BaseObj+1
for i=1 to NumberOfItems
delete object baseobj+i-1
next i
cls 0
exitfunction SelItem
endif
endif
sync
loop
endfunction 0
function PositionHudObject(object,xpos,ypos,zpos)
rem function positions the objects at a position from the screen that means the
rem objects size matches its screen size. i.e a 100x10 dimensioned plain takes
rem up exactly 100x10 pixels
`object=Object Number
`image=Image to use as texture
`xpos=X Position on object
`ypos=Y Position on object
`zpos=Z Position on object
dist#=(screen height()/2)/tan(cameraFOV/2)
if ghost=1 then ghost object on object
if transparency=1 then set object transparency object,2
set object filter object,0 `Do Not MipMap
set object light object,0 `Do not be affected by light
position object object,xpos,ypos,zpos+dist#
endfunction
BTW you could texture the background with another plain of maybe use the command TEXTURE BACKGROUND image number.
I haven't textured the plains because when they move towards the camera any text on them becomes distorted because it is being scaled up. The plains are just used to highlight the selected item.
The text that is being displayed could easily be replaced by a sprite. I will produce a version with media if it's requested.
I look forward to any comments/questions.
Cheers,
Cloggy