Jump to content

Center Image


Slimwaffle
 Share

Recommended Posts

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)

 

Link to comment
Share on other sites

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.

  • Like 2
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...