Wolfsong Posted December 31, 2016 Share Posted December 31, 2016 (edited) For this lesson here: http://www.leadwerks.com/werkspace/page/tutorials/_/loops-r17 I want to see if I'm understanding something right. Though the lesson is about loops (which I do understand) I'm particularly interested in the bits about creating a Window and then a Context (which I'm not sure I understand). ------------ --Create a window window = Window:Create() --Create a rendering context context = Context:Create(window) --While loop while window:KeyHit(Key.Escape)==false do --Set the drawing color and clear the screen context:SetColor(0,0,0) context:Clear() --Set the drawing color and blend mode context:SetColor(1,1,1) context:SetBlendMode(Blend.Alpha) --Draw some text onscreen context:DrawText("PRESS ESCAPE TO END THE PROGRAM.",2,2) --Update the screen context:Sync() end --------------- So, in this example, are we creating a Window which is then identified as 'window' - and then the Window ('window') is being assigned as the Context or "focus" of the following instructions? So, using 'context:SetColor(0,0,0) would be the same as using window:SetColor(0,0,0)? Am I understanding that right? If so (or even if not), why would the line: while window:KeyHit(Key.Escape)==false do not be: while context:KeyHit(Key.Escape)==false do ? Or is hitting the Escape Key something that can only refer directly to 'window' as that relates directly to the actual Window, and not to 'context', since that relates to the variable 'window'? Hopefully I explained that well lol. Anyway, thanks! Edit: Tried to place the code inside Code tags, but it ended up adding a ton of color tags. Edited December 31, 2016 by Wolfsong Quote Link to comment Share on other sites More sharing options...
Genebris Posted December 31, 2016 Share Posted December 31, 2016 Context and Window are different classes, SetColor is a method of Context class: http://www.leadwerks.com/werkspace/page/api-reference/_/context/ KeyHit is in Window class: http://www.leadwerks.com/werkspace/page/api-reference/_/window/ That's why you can't use KeyHit on context and SetColor on window. Quote Link to comment Share on other sites More sharing options...
Wolfsong Posted December 31, 2016 Author Share Posted December 31, 2016 Ahhh I see. So creating a 'context' is creating the viewport inside the window. Got it. Thanks! Quote Link to comment Share on other sites More sharing options...
Rick Posted December 31, 2016 Share Posted December 31, 2016 Context is more like your gfx context. That doesn't take input. A window takes input and handles it while a gfx context handles drawing stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.