Hello all,
I have start to learning LUA and start doing basic LUA like variable, text on screen, Sprites on screen and on.
I was trying to do moving sprites to try move sprite cross the screen but it not working for some reason.
local x = 0
function love.load()
-- Everything will be loaded here
Beast=love.graphics.newImage("Beast.png")
end
function love.update(dt)
-- Everything will be updated here
end
function love.draw(
-- Everything will be drawn here
for x=1, 1, 10 do
love.graphics.draw(Beast,x,10)
end
end
I was trying to do for loop to move sprites cross the screen and I guess for loop in update..........right?
Moving Sprites Cross Screen?
Re: Moving Sprites Cross Screen?
You don't need a for loop to update the position of the sprite. love.draw() is called by the engine every time a new frame is drawn (ideally ~60 times per second) and love.update(dt) is called by the engine every time the game state should be updated, where dt is the time in seconds that passed since love.update was last called. You can just add dt to x inside of love.update and maybe multiply dt by a factor to make the movement faster or slower and simply draw the sprite inside of love.draw at the current position.
Re: Moving Sprites Cross Screen?
Use dt delta time to change the position, position change of x in loop won't be visible as it happens instantly.
https://love2d.org/wiki/dt
https://love2d.org/wiki/dt

-
- Prole
- Posts: 4
- Joined: Sat Apr 19, 2025 10:54 pm
Re: Moving Sprites Cross Screen?
thanks for helping me but I get error which show code blow
Code: Select all
local x = 0
function love.load()
-- Everything will be loaded here
Beast=love.graphics.newImage("Beast.png")
end
function love.update(dt)
-- Everything will be updated here
x=x*dt
end
function love.draw(
-- Everything will be drawn here
love.graphics.draw(Beast,x,10) -- Why Error?
end
Last edited by Lua_Beginner on Tue Apr 22, 2025 6:48 pm, edited 1 time in total.
Re: Moving Sprites Cross Screen?
Please, fix your posting to use full editor/preview and \[code\] formatting.
Code: Select all
code

-
- Prole
- Posts: 4
- Joined: Sat Apr 19, 2025 10:54 pm
Re: Moving Sprites Cross Screen?
It is ok as I got it working.
Code: Select all
local x = 0
function love.load()
-- Everything will be loaded here
Beast=love.graphics.newImage("Beast.png")
end
function love.update(dt)
-- Everything will be updated here
x=x+1-dt
end
function love.draw()
-- Everything will be drawn here
love.graphics.draw(Beast,x,100)
end
Re: Moving Sprites Cross Screen?
Great! Good luck.

Re: Moving Sprites Cross Screen?
It's painful to learn by trial and error like that if you've never used Lua or programmed some games before.
I think it'll speed up your training if you follow a tutorial so you can learn by example.
Here are some cool resources,stolen borrowed from a Reddit thread:
Lua CheatSheet:
https://tylerneylon.com/a/learn-lua/
LÖVE tutorial series (remember you can speed up the video in the player settings, like using 1.5x speed etc):
https://www.youtube.com/playlist?list=P ... qya9Iiefm9
The classic Sheepolution course:
https://sheepolution.com/learn/book/contents
I think it'll speed up your training if you follow a tutorial so you can learn by example.
Here are some cool resources,
Lua CheatSheet:
https://tylerneylon.com/a/learn-lua/
LÖVE tutorial series (remember you can speed up the video in the player settings, like using 1.5x speed etc):
https://www.youtube.com/playlist?list=P ... qya9Iiefm9
The classic Sheepolution course:
https://sheepolution.com/learn/book/contents
-
- Prole
- Posts: 4
- Joined: Sat Apr 19, 2025 10:54 pm
Re: Moving Sprites Cross Screen?
Thanks Dusoft for wishing me good luck 
Thanks RNavega for those interesting tutorials, it gong take bit of time to get used Lua Programming Language and see where it take me from there.

Thanks RNavega for those interesting tutorials, it gong take bit of time to get used Lua Programming Language and see where it take me from there.
Who is online
Users browsing this forum: Ahrefs [Bot] and 6 guests