Help with draw

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
teeter11
Prole
Posts: 27
Joined: Sun Jan 12, 2014 8:48 pm

Help with draw

Post by teeter11 »

I am trying to get the drawings to work right. I cant seem to find whats wrong i am trying to make a bunch of my pictures draw in a row of 10 and idk whats wrong i see the grass appear and then it moves to the right and glitches out
(the code is in the draw function)

Code: Select all

function love.load()
	grass = love.graphics.newImage("images/grasstop.png")
	grassx = 0
	grassy = 300
	num = 0
end

function love.draw()
	for i = 1,10 do
		num =  num + 50
		love.graphics.draw(grass,grassx+num,grassy)
	end
end
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Help with draw

Post by Jasoco »

Because you're moving it 50 pixels every frame, and if your machine is really good then that could be 50 pixels 500-1000 times a second. (Or 60 times a second if you use VSync.)

Look up dt and getDelta. Embrace them. They are your friend.

Edit: LOL, I misunderstood and didn't see that other part. Oh well. What micha says below is correct.
Last edited by Jasoco on Fri May 09, 2014 8:36 am, edited 2 times in total.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Help with draw

Post by micha »

The problem is, that num is a global variable and it gets larger and larger each frame. To fix this you could either reset it to 0 in the beginning of the draw function or you could go completely without:

Code: Select all

function love.draw()
   for i = 1,10 do
      love.graphics.draw(grass,grassx+i*50,grassy)
   end
end
Post Reply

Who is online

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