Page 1 of 1
Getting width and height of a quad
Posted: Sat Mar 10, 2012 5:17 pm
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()
Re: Getting width and height of a quad
Posted: Sat Mar 10, 2012 5:27 pm
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.
Re: Getting width and height of a quad
Posted: Sat Mar 10, 2012 5:47 pm
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.
Re: Getting width and height of a quad
Posted: Sat Mar 10, 2012 5:50 pm
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.
Re: Getting width and height of a quad
Posted: Sat Mar 10, 2012 6:17 pm
by pnzr
Thanks.