Create CanvasGadget(0, 0, 0, 800, 600, )
Well, first I create a image with the needed width and height, CreateImage()
Then I draw all my text on that created image.
With DrawMode() you can select Alpha Image Mode and DrawAlphaImage()
So you can draw transparency text on your background image.
Code: Select all
;---------------------------------------------------------------------------------------------------
;- GLOBALS
;---------------------------------------------------------------------------------------------------
Global Game_Window_Event.i
Global MousePosX.w
Global MousePosY.w
Global GameTextWidth.w
Global GameTextHeight.w
Global GameText.s
Global GameTextFont.i = 4
Global GameBackgroundImage.i = 5
Global GameTextImage.i = 6
;---------------------------------------------------------------------------------------------------
;- LOAD FONTS
;---------------------------------------------------------------------------------------------------
LoadFont(GameTextFont, "Arial", 48, #PB_Font_HighQuality)
;---------------------------------------------------------------------------------------------------
;- PRECREATE IMAGE
;---------------------------------------------------------------------------------------------------
CreateImage(GameBackgroundImage, 800, 600, 32)
StartDrawing(ImageOutput(GameBackgroundImage))
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, 800, 600, RGB(43, 144, 232))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(GameTextFont))
DrawText(100, 100, "PVG Canvas Test", RGB(255, 255, 255))
StopDrawing()
;---------------------------------------------------------------------------------------------------
CreateImage(GameTextImage, 600, 100, 32)
StartDrawing(ImageOutput(GameTextImage))
DrawingFont(FontID(GameTextFont))
GameText = "PVG Canvas Test"
GameTextWidth = TextWidth(GameText) + 10
GameTextHeight = TextHeight(GameText) + 10
DrawingMode(#PB_2DDrawing_Default)
Box(0, 0, GameTextWidth, GameTextHeight, RGB(0, 0, 0))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5, 5, GameText, RGB(255, 255, 255))
;- FOR FULLY TRANSPARENT TEXT (CUT OUT) USE THIS
; DrawingMode(#PB_2DDrawing_AlphaChannel)
; DrawText(5, 5, GameText, RGBA(0, 0, 0, 0))
StopDrawing()
;---------------------------------------------------------------------------------------------------
;- CREATE CANVAS GAMING WINDOW
;---------------------------------------------------------------------------------------------------
If OpenWindow(0, 0, 0, 800, 600, "PVG - Canvas Game Test - v001", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(1, 0, 0, 800, 600, #PB_Canvas_Keyboard)
;---------------------------------------------------------------------------------------------------
;- DO LOOP
;---------------------------------------------------------------------------------------------------
Repeat
Game_Window_Event = WindowEvent()
Select Game_Window_Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ; Canvas gadget
Select EventType()
Case #PB_EventType_LeftButtonDown
If StartDrawing(ImageOutput(GameBackgroundImage))
DrawingMode(#PB_2DDrawing_Default)
DrawAlphaImage(ImageID(GameTextImage), MousePosX, MousePosY, 50)
StopDrawing()
EndIf
Case #PB_EventType_MouseMove
If StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_Default)
; Box(0, 0, 800, 600, RGB(43, 144, 232))
DrawImage(ImageID(GameBackgroundImage), 0, 0, 800, 600)
MousePosX = GetGadgetAttribute(1, #PB_Canvas_MouseX)
MousePosY = GetGadgetAttribute(1, #PB_Canvas_MouseY)
DrawingMode(#PB_2DDrawing_AlphaBlend)
; Circle(MousePosX, MousePosY, 10, RGB(100, 100, 100))
DrawAlphaImage(ImageID(GameTextImage), MousePosX, MousePosY, 50) ;255) ;100)
StopDrawing()
EndIf
EndSelect
EndSelect
EndSelect
Until Game_Window_Event = #PB_Event_CloseWindow
EndIf
;---------------------------------------------------------------------------------------------------
Einde:
End
;---------------------------------------------------------------------------------------------------
- Move the mouse
- LeftMouse button Print on background
You can start with this part
Marc,
EDIT: Tested with WinXP and PB 4.61 Final