[Solved] Silly love.graphics.quad question!

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
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

[Solved] Silly love.graphics.quad question!

Post by ninwa »

(Yes I know one exists already, but) I'm writing a small sprite/animation library, and naturally I'm going to run into issues on the first most trivial thing I write, that said:

Main.lua

Code: Select all

require "Sprite.lua"

function love.load()
	love.graphics.setBackgroundColor(59,185,255) -- gorgeous sky blue color
	grass = Sprite:new(24,12,1,1,"res/grass.png")
end

function love.update(dt)

end

function love.draw()
	-- Draw frame (1,1) to position (50,50)
	grass:drawFrame(1,1,50,50)
end

Sprite.lua

Code: Select all

require "MiddleClass.lua"

Sprite = class('Sprite')

function Sprite:initialize(frame_w, frame_h, cols, rows, file)
	self.sheet = love.graphics.newImage(file)
	self.frame_w = frame_w
	self.frame_h = frame_h
	self.cols = cols
	self.rows = rows
end

-- Draw's a specific frame from location (row,col)
-- in our sheet to the screen at coordinates (x,y)
-- Note: First frame is always (1,1) in the sheet.
function Sprite:drawFrame(row,col,x,y)

	-- Prevent the user from drawing a 
	-- frame that does not exist.
	if row < 1 or col < 1 or
	   row > self.rows or col > self.cols then
	   print("Error (Sprite.lua): You attempted to draw a frame that"..
	         " does not exist within our sprite-sheet.")
	   return false
	end
	
	local blitQuad = love.graphics.newQuad( row-1 * self.frame_w, 
	                                                            col-1 * self.frame_h,
							            self.frame_w, self.frame_h,
								    self.sheet:getWidth(),
								    self.sheet:getHeight() )
									  
	love.graphics.drawq( self.sheet, blitQuad, x, y )
	return true
end
Draws the frame properly, but instead of actually drawing the frame, it just draws a solid block of color.

Halp! :o
<3 Ninwa
Last edited by ninwa on Sun Nov 07, 2010 1:20 am, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Silly love.graphics.quad question!

Post by Robin »

Hm. Is the colour white? (Also, you might not want to create a new Quad every frame, it's a bit wasteful.)
Help us help you: attach a .love.
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: Silly love.graphics.quad question!

Post by ninwa »

Robin wrote:Hm. Is the colour white?
Great point .
Robin wrote:(Also, you might not want to create a new Quad every frame, it's a bit wasteful.)
Actually, green (one of the colors from the sprite I'm performing this on.)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Silly love.graphics.quad question!

Post by Robin »

What happens if you change it to:

Code: Select all

   local blitQuad = love.graphics.newQuad( (row-1) * self.frame_w,
                                                               (col-1) * self.frame_h,
? (I added parentheses.)
Help us help you: attach a .love.
User avatar
ninwa
Party member
Posts: 118
Joined: Tue Oct 12, 2010 1:21 am
Location: Metro Detroit
Contact:

Re: Silly love.graphics.quad question!

Post by ninwa »

Robin wrote:What happens if you change it to:

Code: Select all

   local blitQuad = love.graphics.newQuad( (row-1) * self.frame_w,
                                                               (col-1) * self.frame_h,
? (I added parentheses.)
FML.

Thank you Robin, good eye.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Silly love.graphics.quad question!

Post by Ryne »

ninwa wrote: Thank you Robin, good eye.
The Omniscient are known for their good eyes.
@rynesaur
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 72 guests