TEPA6ANT Posted Tuesday at 03:12 PM Posted Tuesday at 03:12 PM I don't see in the tutorial how to display a texture on the HUD. Let's say I want to display a red cross icon as a health icon and break the Geneva convention In Leadwerks 4 this was done in PostRender(). But how is it done now in Ultra Engine? Quote
Solution Josh Posted Tuesday at 03:14 PM Solution Posted Tuesday at 03:14 PM Use a GUI interface. Set the interface background widget color to 0,0,0,0 to make it transparent. ui.background:SetColor(0,0,0,0) https://www.leadwerks.com/learn/CreateInterface Use Widget:SetIcon or Widget:SetPixmap to display an image on a panel. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
TEPA6ANT Posted Tuesday at 03:48 PM Author Posted Tuesday at 03:48 PM 37 minutes ago, Josh said: Use a GUI interface. Set the interface background widget color to 0,0,0,0 to make it transparent. ui.background:SetColor(0,0,0,0) https://www.leadwerks.com/learn/CreateInterface Use Widget:SetIcon or Widget:SetPixmap to display an image on a panel. I tried some of the methods from the tutorial, but it looks like it should be done on a blank project, because in main.lua it only works with CreateInterface(window), but I can't see the result. And when implementing CreateInterface(world, font, iVec2(256)) in the same main.lua and FPSPlayer.lua, the error “no matching function call takes this number of arguments and the specifies types” was generated Quote
Josh Posted Tuesday at 03:52 PM Posted Tuesday at 03:52 PM I'm sorry, the first argument should be a camera to create the interface on, not a world. This was changed in the release that just came out. I will update the documentation now. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
TEPA6ANT Posted yesterday at 03:52 PM Author Posted yesterday at 03:52 PM Thank you That was a lot harder than Leadwerks 4. In FPSPlayer.lua: ... 23 FPSPlayer.movement = Vec3(0) 24 FPSPlayer.hud = nil ... -- in FPSPlayer:Load 230 if not self.camera then self.camera = CreateCamera(world) self.camera:Listen() end --HUD (START) if properties["hud"] ~= "" then local path = properties["hud"] local prefab = LoadPrefab(world, path) --local temphud = prefab self.hud = prefab --temphud:Instantiate(world) if self.camera then local ui_temp = self.hud:GetComponent("FPSHUD") ui_temp:CheckCamera(self.camera) end end --HUD (END) 248 local pos = entity:GetPosition(true) In FPSPlayer.json add in "properties": { "name": "hud", "label": "HUD Script", "value": "", "filecategory": "PREFAB" } I made a FPSHUD component and FPSHUD.pfb which is a copy of Bullet.pfb, just with a replaced component FPSHUD.lua FPSHUD = {} FPSHUD.name = "FPSHUD" FPSHUD.ui = nil FPSHUD.font = LoadFont("Fonts/arial.ttf") function FPSHUD:Start() end function FPSHUD:Update() if self.ui then local ev = WaitEvent() self.ui:ProcessEvent(ev) end end function FPSHUD:Collide(entity, position, normal, speed) end function FPSHUD:Load(properties, binstream, scene, flags, extra) return true end function FPSHUD:CheckCamera(camera) local window = ActiveWindow() local framebuffer = window:GetFramebuffer() self.ui = CreateInterface(camera, self.font, framebuffer.size) self.ui.background:SetColor(1,0,0,0.1) local pixmap = LoadPixmap("https://raw.githubusercontent.com/Leadwerks/Documentation/master/Assets/Materials/Ground/dirt01.dds") self.ui.background:SetPixmap(pixmap) local sz = self.ui.background:ClientSize() local panel = CreatePanel(50, 50, 256, 50, self.ui.background) panel:SetColor(0, 0, 0, 1) panel:SetLayout(1, 1, 1, 1) panel:SetPixmap(pixmap) end function FPSHUD:Enable() self.enabled = true end function FPSHUD:Disable() self.enabled = false end function FPSHUD:Toggle() if type(self.enabled) == "boolean" and self.enabled == true then self.enabled = false else self.enabled = true end end RegisterComponent("FPSHUD", FPSHUD) return FPSHUD Sure it turned out messy, but my goal for now was just to see how it worked. However, i could probably shove this into one global function and run it from anywhere. That's probably what I'll do in the future. 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.