2d Blitz in Max Gui ?
BlitzMax Forums/BlitzMax Beginners Area/2d Blitz in Max Gui ?
| ||
| I'm trying to create a simple program that I can use traditional 2d blitz with max GUI. But its not working out. for example, in my code I have... If KeyDown(Key_escape) Then End but nothing happens when I hit escape. So do if statments not work for canvasses? what exactly is happening here. What are the rules to using the canvas functions ? Below is a copy of the code. Strict Local MyWindow:Tgadget = CreateWindow("Canvas",200,200,800,600) Local MyCanvas:Tgadget = CreateCanvas(10,10,800,600, Mywindow) SetGraphics CanvasGraphics(MyCanvas) Repeat Cls If KeyDown(Key_escape) Then End PollEvent() Select EventID() Case event_windowclose End End Select Flip Forever |
| ||
How's about this :
Strict
Local MyWindow:Tgadget = CreateWindow("Canvas",200,200,800,600)
Local MyCanvas:Tgadget = CreateCanvas(10,10,800,600, Mywindow)
SetGraphics CanvasGraphics(MyCanvas)
ActivateGadget(MyCanvas) ' enable the canvas gadget
Repeat
Cls
PollEvent()
Select EventID()
Case EVENT_KEYDOWN ' check for "gui" key down events
If EventData() = KEY_ESCAPE Then End
Case event_windowclose
End
End Select
Flip
Forever
See how the GUI handles the key events. |
| ||
You may want to run the canvas update off a timer instead.
Strict
Local MyWindow:Tgadget = CreateWindow("Canvas",200,200,800,600)
Local MyCanvas:Tgadget = CreateCanvas(10,10,800,600, Mywindow)
SetGraphics CanvasGraphics(MyCanvas)
ActivateGadget(MyCanvas) ' enable the canvas gadget
Local timer:TTimer = TTimer.Create(60) ' 60 FPS timer (or there abouts)
Repeat
WaitEvent()
Select EventID()
Case EVENT_TIMERTICK '
RedrawGadget(MyCanvas)
Case EVENT_GADGETPAINT
Cls
' draw stuff here
Flip
Case EVENT_KEYDOWN ' check for "gui" key down events
If EventData() = KEY_ESCAPE Then End
Case event_windowclose
End
End Select
Flip
Forever
Your version sucks up 100% of my CPU time. This version appears to idle between 8 and 16% on my computer. Just a thought :-) |
| ||
| Same thing happened to me when starting to use MaxGUI. The problem is the lack of the "WaitEvent" command, otherwise it'll just loop forever using up all your CPU. |
| ||
| Or use EnablePolledInput() which will not tokenise/hilite in the IDE but will work to switch on normal keypresses if you dont want to use events. |