Jump to content

[Leadwerks 3 Steam Version] DrawImage() crash


X54321
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

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