Getting width and height of a quad

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
pnzr
Prole
Posts: 3
Joined: Sat Mar 10, 2012 3:51 pm

Getting width and height of a quad

Post by pnzr »

I have few quads of various size created from the same tileset. How can I get width or height of specific quad?
I tried this but it didn't work:

Code: Select all

quad_box = love.graphics.newQuad(0, 0, 50, 50, img_tileset:getWidth(), img_tileset:getHeight())
x = quad_box:getHeight()
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Getting width and height of a quad

Post by tentus »

I may be misremembering, since I don't use quads much, but isn't part of the point of them that they don't have hard-and-fast widths or heights? When I do use quads, I use them to render a tiling image, and keep the width I want in a separate variable.
Kurosuke needs beta testers
pnzr
Prole
Posts: 3
Joined: Sat Mar 10, 2012 3:51 pm

Re: Getting width and height of a quad

Post by pnzr »

I just wanted to use single tileset for all game graphics. Maybe it is a bad idea? I need width and height to do collision detection.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Getting width and height of a quad

Post by tentus »

There's nothing wrong with using a single tileset (that I know of, anyhow). I would recommend keeping width and height in their own variables, which you define before you even make the quads- that way your source isn't full of magic numbers.

As an example, here's an entity declaration from a game I was making with my roommate:

Code: Select all

solid = class { function(self, x, y, w, h, img)
	self.width = w or 64
	self.height = h or 64
	self.shape = collider:addRectangle(x - (self.width / 2), y - (self.height / 2), self.width, self.height)
	collider:setPassive(self.shape)
	self.img = img or "rock"
	if img[self.img] == nil then
		img[self.img] = love.graphics.newImage("media/ents/".. self.img ..".png")
		img[self.img]:setWrap("repeat", "repeat")
	end
	self.quad = love.graphics.newQuad(0, 0, self.width, self.height, 64, 64)
end }
I'm using HardonCollider for collision, but I'm also keeping width and height on hand (both variables also have defaults of 64, in case something goes wrong in my level file). I then set the image name, and check that said image is loaded- if not I load it into my img table and set it to wrap on both axes. Finally, I make a quad and use the width and height already defined to make it work.

It's not exactly what you're talking about, but kinda close.
Kurosuke needs beta testers
pnzr
Prole
Posts: 3
Joined: Sat Mar 10, 2012 3:51 pm

Re: Getting width and height of a quad

Post by pnzr »

Thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest