Slimwaffle Posted December 24, 2018 Share Posted December 24, 2018 Hey guys. I was looking on the forums to find a way to center a drawn image. Couldn't find a solution. I figured it out and then thought hey this might be useful. So I am going to post some code here. You guys might find easier ways to do this. But whatevs hope this helps someone. local a = self.player.script.stamina local b = self.player.script.maxstamina local d = self.staminaBarColor local e = a / b local sx = 70 local sy = 10 local hbc = self.staminabarbackColor local ix = 105 local iy = 5 local c1 = 90 * e local ix2 = ix + (90 - c1) / 2 local iy2 = iy + (90 - c1) / 2 --Background Square context:SetColor(0.2,0.2,0.2,1) context:DrawRect(105, 5, 90 , 90) context:SetColor(1,1,1,1) context:DrawImage(self.run ,ix2, iy2, c1 , c1) Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 24, 2018 Share Posted December 24, 2018 Thanks for posting. You can use GetWidth and GetHeight on a texture and use that information to center an image. In C, it would look something like this: context->DrawImage(texture, x-texture->GetWidth()/2, y-texture->GetHeight()/2, texture->GetWidth(), texture->GetHeight()); Where x and y are the coordinates you want the image centered on. 2 Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted December 24, 2018 Author Share Posted December 24, 2018 Thanks mate that looks like a way better way of doing it Quote Link to comment Share on other sites More sharing options...
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.