Page 1 of 1

Quad Help

Posted: Sat Feb 21, 2015 8:36 pm
by OdnsRvns
I have a list of quads for a small kids game. I wanted to know how would be the best way to pull out each variable in the quad and assign it to another variable.

Code: Select all

gr, down  = love.graphics, love.keyboard.isDown

q_state = 0
q_zero = gr.newQuad(0, 0, 128, 128, img.sprite:getDimensions())
q_one  = gr.newQuad(128, 0, 128, 128, img.sprite:getDimensions())
q_one = gr.newQuad(128, 0, 128, 128, img.sprite:getDimensions())
q_two = gr.newQuad(256, 0, 128, 128, img.sprite:getDimensions())
q_three = gr.newQuad(384, 0, 128, 128, img.sprite:getDimensions())

if key == "n" then q_state = q_state + 1 end

if q_state == 0 then q_display = q_zer0 end
if q_state == 1 then q_display = q_one end
-- ---QUESTION????----
-- now how do I get each variable out of q_display so i can use them

gr.draw( img.sprite, q_display, x, y )


Re: Quad Help

Posted: Sat Feb 21, 2015 9:08 pm
by Azhukar

Code: Select all

local gr, down  = love.graphics, love.keyboard.isDown

local spriteDimensions = img.sprite:getDimensions()

local quads = {
	gr.newQuad(0,0,128,128,spriteDimensions)
	gr.newQuad(128,0,128,128,spriteDimensions)
	gr.newQuad(256,0,128,128,spriteDimensions)
	gr.newQuad(384,0,128,128,spriteDimensions)
}

local q_state = 0
if (key == "n") then
	q_state = q_state + 1
end
gr.draw(img.sprite, quads[1 + q_state % #quads],x,y)

Re: Quad Help

Posted: Sat Feb 21, 2015 9:16 pm
by OdnsRvns
I'm not sure I explained myself very well. I want to get the values of q_display and set them to a variable.

q_display_x, q_display_y, q_display_w ect... this way i can always know how large the quad is I'm displaying. I'm going to use this for hitboxes/mouseovers/ect...

Re: Quad Help

Posted: Sat Feb 21, 2015 9:26 pm
by DaedalusYoung
[wiki]Quad:getViewport[/wiki]?

Re: Quad Help

Posted: Sat Feb 21, 2015 11:08 pm
by OdnsRvns
DaedalusYoung wrote:[wiki]Quad:getViewport[/wiki]?
Shit son this maybe exactly what I need. When I get home I'll try it out. I'm not sure how I missed the Wiki on this. Thank you very much.