Hey I'm just starting off in love working my way around lua
I'm very familiar when it comes to design scripting and creating games in other engines without a problem. I'm trying to figure out how to create a sprite/object to use as my player. a point the right direction would help me out a lot.
Sprites, Objects the works?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Sprites, Objects the works?
The simplest way would be to make a table (think of it as an object, in this case), let's call it "player", which stores the player's position, graphic, health, and whatnot.
And then draw the player in your love.draw() function:
And there you go - a player with a position, a graphic, and a health value. Add some code to love.update(dt) to make it move around, and you're off to a fine start.
Code: Select all
player.x = 100
player.y = 200
player.image = love.graphics.newImage("player.png")
player.health = 100
Code: Select all
function love.draw()
love.graphics.draw( player.image, player.x, player.y, 0, 1, 1, 0, 0) )
end
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
-
- Prole
- Posts: 8
- Joined: Wed Jan 27, 2010 7:29 am
Re: Sprites, Objects the works?
you are totally awesome that is exactly what I was looking for.
-
- Prole
- Posts: 8
- Joined: Wed Jan 27, 2010 7:29 am
Re: Sprites, Objects the works?
ok cool now I got a movable little smiley face. how about animated sprites and please don't tell me gif images. I'm saying like either using 1 image like a tileset of images for the character with all their animations in it. if it's supported. or how to use multiple external images to create my animation.
I have theory for how it would work with multiple images.
something like
and then have each frame of the animation like Face0.png, Face1.png and so on.
would that work or is there a better method?
don't mind my syntax I'm still learning Lua.
I have theory for how it would work with multiple images.
something like
Code: Select all
EndFrame=10
Frame =0
Player.image = love.graphics.newImage("Face"+Frame+".png")
function love.update(dt)
Frame = Frame+1
if Frame > EndFrame Then
Frame =0
end
}
function love.draw()
love.graphics.draw( Player.image, Player.x, Player.y, 3.14, 1, 1, 0, 0)
end
would that work or is there a better method?
don't mind my syntax I'm still learning Lua.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Sprites, Objects the works?
Lots of syntax errors indeed.
If I would write the exact thing you were trying to do, I would to it this way:
Disclaimer: completely untested, blablabla
If I would write the exact thing you were trying to do, I would to it this way:
Code: Select all
function love.load()
EndFrame=10
Frame = 1
Images = {}
for i=1,EndFrame do
Images[i] = love.graphics.newImage("Face"..i..".png") -- + doesn't work on strings
end
Player = {x = 300, y = 200}
end
function love.update(dt)
Frame = Frame % EndFrame + 1
end
function love.draw()
love.graphics.draw(Images[Frame], Player.x, Player.y, 3.14, 1, 1, 0, 0)
end
Help us help you: attach a .love.
-
- Prole
- Posts: 8
- Joined: Wed Jan 27, 2010 7:29 am
Re: Sprites, Objects the works?
oh ok so I did sort of have an idea how it would work. yes putting it in a array would make more since.
so adding variables to strings is kinda like php syntax.
so adding variables to strings is kinda like php syntax.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests