Jump to content

Lua AddHook for an Object


ParaToxic
 Share

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

Link to comment
Share on other sites

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

Elite Cobra Squad

Link to comment
Share on other sites

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.

  • Upvote 1

 

 

Link to comment
Share on other sites

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.

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.

 Share

×
×
  • Create New...