X54321 Posted February 2, 2014 Posted February 2, 2014 I'm trying to draw a weapon overlay for my game; I already have the texture for it imported and in the right place, but whenever I actually draw it the game crashes. No errors, nothing. The .tex settings for it is the default except all checkboxes are unchecked and the filter mode is set to 'pixel'. Here's the part where I draw the image: local window = Window:GetCurrent() local forward = 0 local strafe = 0 local angle = 0 local weapon = 0 function Script:Create() self.w1 = Texture:Load("Materials/HUD/gun_overlay.tex") end function Script:UpdateWorld() window = Window:GetCurrent() angle = angle - dx * 0.25 forward = (window:KeyDown(Key.W) and 1 or 0)*6 - (window:KeyDown(Key.S) and 1 or 0) * 6 strafe = (window:KeyDown(Key.D) and 1 or 0)*6 - (window:KeyDown(Key.A) and 1 or 0) * 6 self.entity:SetInput(angle, forward, strafe, 0, false) end function Script:EquipBlaster()--in weapon = 1 end function Script:PostRender(context) context:SetBlendMode(Blend.Alpha) context:SetColor(1,1,1,1) if weapon == 1 then context:DrawImage(self.w1, 52, 52) end end Quote
Josh Posted February 2, 2014 Posted February 2, 2014 Set a breakpoint and make sure the image isn't nil. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
X54321 Posted February 2, 2014 Author Posted February 2, 2014 Set a breakpoint and make sure the image isn't nil. Yes, the image is nil. I have double-checked and the path is correct and the file is still there. Furthermore, I have tried other textures and got the same result. Quote
Rick Posted February 2, 2014 Posted February 2, 2014 You are setting that variable in Script:Create(). Try moving it to Script:Start() which is the function that all entity scripts call on startup. Not sure where you got Create() from. Quote
X54321 Posted February 2, 2014 Author Posted February 2, 2014 You are setting that variable in Script:Create(). Try moving it to Script:Start() which is the function that all entity scripts call on startup. Not sure where you got Create() from. Thanks, it worked! Not sure why; I'll have to look at the documentation. 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.