Petit code 3D qui affiche un cube ainsi qu'un ButtonScreenGadget() (Nouveauté PB 6.30)
Ce bouton est testé dans une boucle évènementielle de cette manière.
Code : Tout sélectionner
; Traiter les evenements ScreenWindow
If ScreenWindowEvent() = #PB_Event_Gadget
Select EventScreenGadget()
Case #clickMe
Debug "Bouton clickMe sélectionné"
EndSelect
EndIf
■ Je clique sur le bouton ClickMe et j'ai un message message m'avertissant que j'ai cliqué sur le bouton ClickMe. C'est normal
■ Si je clique par la suite n'importe ou sur l'écran j'ai malheureusement le même message
Code : Tout sélectionner
EnableExplicit
Enumeration
#clickMe
EndEnumeration
; DPI Resolution
Global drx.f, dry.f
; Evenement window
Global Event, ScreenGadget
; Sprite Help
Global Bottom, FontInfo = LoadFont(#PB_Any, "Arial", 12)
Global FPS
; Initialisation de l'environnement 3D
If InitEngine3D(#PB_Engine3D_DebugLog) = 0 Or InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Information", "Souci d'initialisation environnement 3D")
EndIf
drx = DesktopResolutionX()
dry = DesktopResolutionY()
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_Maximize | #PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0),0, 0, WindowWidth(0)*drx , WindowHeight(0)*dry, 0, 0, 0, #PB_Screen_WaitSynchronization)
InitScreenGadgets()
ButtonScreenGadget(#clickMe, 10, 10, 100, 50, "Click Me")
; Clavier international
KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
; Camera
CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(0, 139, 139))
MoveCamera(0, 3, 6, 10, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
; Light
AmbientColor(RGB(255, 165, 0))
CreateLight(0, $ffffff, -5, 10, 10)
; Un cube
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
;- Création du sprite Help
Bottom = CreateSprite(#PB_Any, ScreenWidth(), 150, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(Bottom))
DrawingFont(FontID(FontInfo))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0, 0, ScreenWidth(), SpriteHeight(Bottom), RGBA(0, 0, 0, 140))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, ". : : Help : : .")
DrawText(10, 40, "Touche Escape pour quitter.")
StopDrawing()
EndIf
; Boucle evenementielle
Repeat
; Traiter les évenement windows de la file d'attente
While WindowEvent():Wend
; Traiter les evenements ScreenWindow
If ScreenWindowEvent() = #PB_Event_Gadget
Select EventScreenGadget()
Case #clickMe
Debug "Bouton clickMe sélectionné"
EndSelect
EndIf
; Evenements 2D/3D
ExamineKeyboard()
ExamineMouse()
; Rendu 3D
RenderWorld()
; Rendu 2D
DisplayTransparentSprite(Bottom, 0, ScreenHeight()-SpriteHeight(Bottom))
; Rendu screengadgets
RenderScreenGadgets()
; Basculement ancienne image / nouvelle image du rendu final
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
D'avance merci.