Randomly Generated Images Not Drawing

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
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Randomly Generated Images Not Drawing

Post by kylewatson98 »

I am working on a project and I have came across a bug but I don't know how to fix it :/ Take a look:

Code: Select all

clouds = {}
clouds.__index = clouds

function clouds.init()
	local cld = {}
	setmetatable(cld, clouds)
	cld.batch = {}
	for i=1, 9 do
		table.insert(cld.batch, {love.graphics.newImage("graphics/cloud"..math.random(3)..".png"), math.random(width - 32), (i - 1)*1.92})
	end
	cld.v = 1
	return cld
end

function clouds:draw()
	love.graphics.setColor(255,255,255,255)
	for i=1, #self.batch do
		love.graphics.draw(self.batch[i][1], self.batch[i][2], self.batch[i][3])
	end
end

function clouds:update(dt)
	for i=1, #self.batch do
		self.batch[i][3] = self.batch[i][3] + self.v * 20
		if self.batch[i][3] < -16 then
			self.batch[i][3] = height
			self.batch[i][2] = math.random(width - 32)
			self.batch[i][1] = love.graphics.newImage("graphics/cloud"..math.random(3)..".png")
		end
	end
	
	if self.v < 10 then
		self.v = self.v + dt
	end
end
My canvas is scaled 8x8 and what I am trying to happen is the image to load up randomly spread down the height of the screen, they travel upwards until off the screen to then change image and start from the bottom again. I have passed all the right functions into the callback functions but I still don't know whats wrong.
Please help me. Thanks in advance, Kyle.
LÖVE dem beats
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Randomly Generated Images Not Drawing

Post by Robin »

Could you explain what does happen?

Also, in the future upload a .love.
Help us help you: attach a .love.
User avatar
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Re: Randomly Generated Images Not Drawing

Post by kylewatson98 »

Like it clearly states in the title, the randomly generated images do not show up...
I will just upload my give my main.lua code because that is the only thing that uses this class.

Code: Select all

function love.load()
	require "class/whale"
	require "class/clouds"
	require "class/cut1"
	require "class/speechB"
	height = 75
	width = 100
	love.graphics.setLine(1, "rough")
	love.graphics.setBackgroundColor(130, 220, 255)
	love.graphics.setDefaultImageFilter("nearest", "nearest")
	love.graphics.setFont(love.graphics.newImageFont("graphics/font.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\""))
	whale = whale:init()
	clouds = clouds:init()
	cut1 = cut1:init()
	speechB = speechB:init()
end

function love.draw()
	love.graphics.scale(8, 8)
	whale:draw()
	clouds:draw()
	cut1:draw()
	speechB:draw()
	love.graphics.print(love.timer.getFPS(), 1, 1, 0, 0.125, 0.125)
end

function love.update(dt)
	whale:update(dt)
	clouds:update(dt)
	--cut1:update(dt)
end

function love.keyreleased(k)
	whale:keypressed(k)
end
LÖVE dem beats
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Randomly Generated Images Not Drawing

Post by Robin »

If you upload a .love, both the probability someone helps you is greatly increased and the average time before someone helps you is greatly reduced.

I've tried to find the solution, but without a .love I cannot do more.
Help us help you: attach a .love.
User avatar
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Re: Randomly Generated Images Not Drawing

Post by kylewatson98 »

https://www.dropbox.com/s/ohwayhc7jn7hb ... round.love
Sorry, didn't realise, kinda tired last night.
LÖVE dem beats
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Randomly Generated Images Not Drawing

Post by Zeliarden »

Yo!
You are drawning the clouds outside of the screen
change the code

Code: Select all

self.batch[i][3] = self.batch[i][3] + self.v * 20
to

Code: Select all

self.batch[i][2] = self.batch[i][2] + self.v
for moving clouds

I recommended that you only use love.graphics.newImage once per image
something like:

Code: Select all

cloud[1] = love.graphics.newImage("graphics/cloud1.png")
cloud[2] = love.graphics.newImage("graphics/cloud2.png")
cloud[3] = love.graphics.newImage("graphics/cloud3.png")
...
self.batch[i][1] = cloud[math.random(3)]
User avatar
kylewatson98
Prole
Posts: 13
Joined: Thu Feb 28, 2013 9:02 pm

Re: Randomly Generated Images Not Drawing

Post by kylewatson98 »

Thanks a bunch :3 Also great idea, just a little more efficient :ultraglee:
LÖVE dem beats
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests