Jump to content
ParaToxic

Lua AddHook for an Object

Recommended Posts

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

Share this post


Link to post

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

Share this post


Link to post

@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.

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...