You're overwriting your variables. You should probably read through the PiL.mrpoptart wrote:Thank you nevon. It worked like a charm. But now my tank will now move in the image at all. here is my code, can you help me see what is wrong?
Newbie here gonna start out small
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Newbie here gonna start out small
Re: Newbie here gonna start out small
Thank you for your help. I will read through this and see if i can find my error.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Newbie here gonna start out small
Argh, this legal world of ours is more wacky than I thought.nevon wrote:Depends. See Threshold of Originality. In general though, no, just because you post something on the interwebs, that doesn't mean it automagically becomes public domain.BlackBulletIV wrote:Nah I was meaning the real "use", as in put in your game. One thing I did forget though, is conflicting licenses, not just licenses saying "look, but don't touch."Oh really? Didn't know that. What about the code snippets we post? It'd be public domain unless otherwise stated I'm guessing?Robin wrote:Also remember: games without a license are subject to full copyright. Luckily, most of the useful code around here is open source.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Newbie here gonna start out small
Let's see your love.load function:
You start by creating a variable called "tank" and assign an image to it. Then you create x,y and speed, with values 500,500 and 100.
Then you create background, with another image.
And then you reset x,y and speed to 0,0,0
You are re-using x,y and speed for both the tank and the background. If you want the tank to move differently from the background, you need to use different variables for it. Try calling the tank variables tank_x, tank_y and tank_speed - in all your functions, not only love.load. This should give you a nice moving tank.
Code: Select all
function love.load()
tank = love.graphics.newImage("tank.png")
x = 500
y = 500
speed = 100 ;
background = love.graphics.newImage("background.png")
x = 0
y = 0
speed = 0
end
Then you create background, with another image.
And then you reset x,y and speed to 0,0,0
You are re-using x,y and speed for both the tank and the background. If you want the tank to move differently from the background, you need to use different variables for it. Try calling the tank variables tank_x, tank_y and tank_speed - in all your functions, not only love.load. This should give you a nice moving tank.
When I write def I mean function.
Re: Newbie here gonna start out small
Well thank you a bunch kikito. I redid my code, and it works like a charm. Now im on my way to some collision detection, and shooting some missiles.
here is the code that i redid and it worked, with your help.
here is the code that i redid and it worked, with your help.
Code: Select all
function love.load()
tank = love.graphics.newImage("tank.png")
x = 500
y = 500
speed = 100 ;
background = love.graphics.newImage("background.png")
bg_x = 0
bg_y = 0
bg_speed = 0
end
function love.update(dt)
if love.keyboard.isDown("right") then
x = x + (speed * dt)
elseif love.keyboard.isDown("left") then
x = x - (speed * dt)
end
if love.keyboard.isDown( "escape" ) then
love.event.push( "q" )
end
end
function love.draw()
love.graphics.draw(background, bg_x, bg_y)
love.graphics.draw(tank, x, y)
end
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Newbie here gonna start out small
When your game starts getting more complex, you'll want to look into tables. That will allow you to have objects, in a sense, which contain their own data. So instead of needing new global variables for everything, you can call, for instance, tank.x = tank.speed*100*dt. It would also allow you to have arbitrary numbers of enemies. In general, tables are the best part of Lua, in my humble opinion.
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+.
Re: Newbie here gonna start out small
Taehl wrote:When your game starts getting more complex, you'll want to look into tables. That will allow you to have objects, in a sense, which contain their own data. So instead of needing new global variables for everything, you can call, for instance, tank.x = tank.speed*100*dt. It would also allow you to have arbitrary numbers of enemies. In general, tables are the best part of Lua, in my humble opinion.
..... metatables???
"We do not stop playing because we grow old. We grow old because we stop playing." -- Unknown
Who is online
Users browsing this forum: No registered users and 42 guests