DarkBasic Pro is certainl a lot of fun.
After being used to managing 2D buffers in Pygame, it is a delight to find a 2D/3D engine that has the same kind of power.
Here's a conversion of one of my Pygame functions to DarkBasic, that generates buttons on the fly, with a single function call. Instead of creating image buttons in an image painter, the game or simulation can make it's own buttons 'on the fly' whenever they are needed.
Enjoy.
`MakeSpriteButton Function
`Make sprite buttons on the fly with a simple function call.
`Provide a sprite number and an image number to use, and the
`..function will build the button on the sprite for you yo use
`Function Paramaters:
`spriteNo: The number of the sprite to use
`imageNo: The number of the image to use
`width: Width of button
`height: height of nutton
`inkR: The base Red color for the button
`inkG: The base Green color for the button
`inkB: The base Blue color for the button
`buttonText$: The text to place on the button
`Notes:
`The current font used is "Arial", but this can easily be changed
`The current format creates and 'indented' text, this can easliy be changed
`The color gradient is invremented, this can also be reversed.
`Author: [email protected]
SYNC ON
spriteNo1 = 101
imageNo1 = 201
MakeSpriteButton(spriteNo1,imageNo1,120,30,200,10,10,"START")
spriteNo2 = 102
imageNo2 = 202
MakeSpriteButton(spriteNo2,imageNo2,120,30,0,100,10,"OPTIONS")
spriteNo3 = 103
imageNo3 = 203
MakeSpriteButton(spriteNo3,imageNo3,160,25,100,50,200,"Dynamic Button")
spriteNo4 = 104
imageNo4 = 204
MakeSpriteButton(spriteNo4,imageNo4,200,20,100,100,240,"Make them any size")
spriteNo5 = 105
imageNo5 = 205
MakeSpriteButton(spriteNo5,imageNo5,250,60,0,100,240,"BIG")
DO
PASTE SPRITE spriteNo1,200,100
PASTE SPRITE spriteNo2,200,140
PASTE SPRITE spriteNo3,200,180
PASTE SPRITE spriteNo4,100,210
PASTE SPRITE spriteNo5,100,250
SYNC
LOOP
END
FUNCTION MakeSpriteButton(spriteNo,imageNo,width,height,inkR,inkG,inkB,buttonText$)
INK RGB(inkR,inkG,inkB),0
left = 0
top = 0
CREATE BITMAP 31,width,height
FOR i = 0 TO 180
r = height/2
x = SIN(i)*r
y = COS(i)*r
x1 = left + r - x
x2 = left + width - r + x
y = top + y + r
INC inkR
IF inkR > 255 THEN inkR = 255
INC inkG
IF inkG > 255 THEN inkG = 255
INC inkB
IF inkB > 255 THEN inkB = 255
INK RGB(inkR,inkG,inkB),0
LINE x1,y,x2,y
NEXT i
SET TEXT FONT "ariel"
SET TEXT SIZE height - 5
INK RGB(0,0,0),0
SET TEXT TO BOLD
sz = TEXT SIZE()
txtTop = top + (height - sz)/2 +1
BLUR BITMAP 31,3
INK RGB(255,255,255),0
CENTER TEXT width/2+1,txtTop+1,buttonText$
INK RGB(0,0,0),0
CENTER TEXT width/2,txtTop,buttonText$
GET IMAGE imageNo,0,0,width,height
SET CURRENT BITMAP 0
DELETE BITMAP 31
SPRITE spriteNo,-1000,-1001,imageNo
ENDFUNCTION