Post by StevenE on Jun 3, 2004 16:21:04 GMT -5
The following demo code is a very simple start to a pop-up type control console for a game. It remains "hidden" to allow full screen game graphics and then "pops up" when the mouse drops down to it. I do not currently have any selection of menu items available.
As I am just starting to try out Basic4GL, I would like any comments on if I am reinventing the wheel, or going a roundabout way to do something that can be done in a more simple way.
You will need two graphics to complete the demo. Use any 32x32 image for the mouse and create a 600x64 box of any color to simulate the popup console.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' Test for loading custom mouse cursor
' and control the sprite with the mouse
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' Set new texture for custom mouse pointer
' using a 32x32 graphic with the hot spot
' at the very top, left corner. The mouse
' graphic will be set to display as partially
' tranparent
dim mousetexture, mousepointer
mousetexture = LoadTexture ("cursor01.png")
mousepointer = NewSprite (mousetexture)
SprSetAlpha (.75)
SprSetXCentre (0)
SprSetYCentre (0)
' Set new texture for pop-up mouse console
' using a 600x64 graphic. Initially, the
' image will be located below the visual
' area of the screen. The image will also
' be centered on the X axis of the screen
dim consoletexture, consolepop
consoletexture = LoadTexture ("console.png")
consolepop = NewSprite (consoletexture)
SprSetSize ( 600, 64 )
SprSetXCentre (0)
SprSetYCentre (0)
SprSetPos ( (SpriteAreaWidth () - SprXSize () ) / 2, SpriteAreaHeight () )
' Define a few variables for settings and
' to cut down on repeated calculations that
' shouldn't change
dim consoleshow
dim pointerx, pointery
' Initially set our console for not shown
consoleshow = false
' Begin main "infinite" program loop
while true
' calculate the current position of our
' custom mouse pointer
pointerx = Mouse_X () * SpriteAreaWidth ()
pointery = Mouse_Y () * SpriteAreaHeight ()
' display our custom mouse on the screen
BindSprite ( mousepointer )
SprSetPos (pointerx, pointery)
' check on console pop-up activation
if not consoleshow and pointery > SpriteAreaHeight () - 16 then
' popup the console
consoleshow = true
' bind our console sprite
BindSprite ( consolepop )
' set the sprite as visible at bottom of screen
SprSetY ( SpriteAreaHeight () - 64 )
endif
' check for console pop-up deactivation
if consoleshow and pointery < SprY (consolepop) then
' hide the console
consoleshow = false
' bind our sprite
BindSprite ( consolepop )
' set the sprite below visible screen area.
SprSetY ( SpriteAreaHeight () )
endif
wend
' Official "end" of the program
end
As I am just starting to try out Basic4GL, I would like any comments on if I am reinventing the wheel, or going a roundabout way to do something that can be done in a more simple way.
You will need two graphics to complete the demo. Use any 32x32 image for the mouse and create a 600x64 box of any color to simulate the popup console.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' Test for loading custom mouse cursor
' and control the sprite with the mouse
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' Set new texture for custom mouse pointer
' using a 32x32 graphic with the hot spot
' at the very top, left corner. The mouse
' graphic will be set to display as partially
' tranparent
dim mousetexture, mousepointer
mousetexture = LoadTexture ("cursor01.png")
mousepointer = NewSprite (mousetexture)
SprSetAlpha (.75)
SprSetXCentre (0)
SprSetYCentre (0)
' Set new texture for pop-up mouse console
' using a 600x64 graphic. Initially, the
' image will be located below the visual
' area of the screen. The image will also
' be centered on the X axis of the screen
dim consoletexture, consolepop
consoletexture = LoadTexture ("console.png")
consolepop = NewSprite (consoletexture)
SprSetSize ( 600, 64 )
SprSetXCentre (0)
SprSetYCentre (0)
SprSetPos ( (SpriteAreaWidth () - SprXSize () ) / 2, SpriteAreaHeight () )
' Define a few variables for settings and
' to cut down on repeated calculations that
' shouldn't change
dim consoleshow
dim pointerx, pointery
' Initially set our console for not shown
consoleshow = false
' Begin main "infinite" program loop
while true
' calculate the current position of our
' custom mouse pointer
pointerx = Mouse_X () * SpriteAreaWidth ()
pointery = Mouse_Y () * SpriteAreaHeight ()
' display our custom mouse on the screen
BindSprite ( mousepointer )
SprSetPos (pointerx, pointery)
' check on console pop-up activation
if not consoleshow and pointery > SpriteAreaHeight () - 16 then
' popup the console
consoleshow = true
' bind our console sprite
BindSprite ( consolepop )
' set the sprite as visible at bottom of screen
SprSetY ( SpriteAreaHeight () - 64 )
endif
' check for console pop-up deactivation
if consoleshow and pointery < SprY (consolepop) then
' hide the console
consoleshow = false
' bind our sprite
BindSprite ( consolepop )
' set the sprite below visible screen area.
SprSetY ( SpriteAreaHeight () )
endif
wend
' Official "end" of the program
end