ParaToxic Posted May 29, 2014 Posted May 29, 2014 Hey guys after a long break I want to create a new little game and learn a bit about scripting in lua. I want to create a 2D HUD entitie with a script that for example draws "Press the F key to..." if I collide with a Collider. But I realized that I cant use the AddHook function inside of an object. How can I use drawing functions like DrawText in the objects script ?? Thanks Quote
josk Posted May 29, 2014 Posted May 29, 2014 In your object script there should be a PostRender function function Script:PostRender(context) App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(0,1,0,1.0) App.context:DrawText("Value: "..self.val, 100, 100) App.context:SetBlendMode(Blend.Solid) end Quote Elite Cobra Squad
Rick Posted May 29, 2014 Posted May 29, 2014 @josk I think you can just use the passed in variable 'context'. self.context and context would be different variables where if the context variable doesn't work then it's a bug. Quote
josk Posted May 29, 2014 Posted May 29, 2014 So you can, learn something new every day. Thanks. Quote Elite Cobra Squad
Admin Posted May 29, 2014 Posted May 29, 2014 In your object script there should be a PostRender function function Script:PostRender(context) App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(0,1,0,1.0) App.context:DrawText("Value: "..self.val, 100, 100) App.context:SetBlendMode(Blend.Solid) end Keep in mind that App.context might not exist, if the script is running in a C++ program. So it's best to just use the function argument context. 1 Quote
ParaToxic Posted May 29, 2014 Author Posted May 29, 2014 Oh sorry I didn't mention that I use Leadwerks Engine 2...:/ Quote
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.