Maybe I can help you ?
I am here not so long ago, but in the programming of years.
Exactly what you want to do ?
jumping tutorial?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
i am having problems with loading pictures right now
take a look at page 2 i posted my problems there
take a look at page 2 i posted my problems there
Re: jumping tutorial?
Try this code.
Code: Select all
function love.load()
image = love.graphics.newImage("X.png");
end
function love.draw()
love.graphics.draw(image, 10, 10, 0, 1, 1, 0, 0);
end
Re: jumping tutorial?
toaster468 wrote:what i have right now:
Code: Select all
-- Office Man Stan -- function love.load() love.graphics.setMode(320, 320) love.graphics.setCaption( "Office Man Stan" ) stan = love.graphics.newImage( "img/P.PNG" ) ground = love.graphics.newImage( "img/X.PNG" ) end function love.update(dt) end function love.draw() love.graphics.draw( stan, 50, 50 ) love.graphics.draw( ground, 0, 240 ) end
It shouldnt.toaster468 wrote:but it works when i am only calling 1 picture
You dont have your images in an "img" directory. You could try either putting the images in a folder called "img" or removing "img/" from your sources and keep the images as they are, in the root of the program.
EDIT
Sorry, Didn't realize there was another page to this thread, it seems the question was already answered.
@rynesaur
Re: jumping tutorial?
Happened or not ?
And where are you now ?
And where are you now ?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Do they have exactly the same name? Including lowercase and uppercase letters, as well as the extension? (billy.JPG is not the same as billy.jpg) .
If you don't find the issue, paste your code here with a screenshot of your game folder with the images.
EDIT: also, I'd advise you to configure the windows explorer so it shows file extensions on the file names. If I remember correctly, it tells you that your 'png' and 'PNG' files are all of type 'PNG' so you might not see the error.
And yes, if you don't have an img folder inside your game folder, you should not add it on the code.
If you don't find the issue, paste your code here with a screenshot of your game folder with the images.
EDIT: also, I'd advise you to configure the windows explorer so it shows file extensions on the file names. If I remember correctly, it tells you that your 'png' and 'PNG' files are all of type 'PNG' so you might not see the error.
And yes, if you don't have an img folder inside your game folder, you should not add it on the code.
When I write def I mean function.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
WOO! It works thanks a bunch guys!
Alright now onto the rest of my lesson, what is the next step?
Alright now onto the rest of my lesson, what is the next step?
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: jumping tutorial?
I would look over these two tutorials next before trying to implement a jump.
http://love2d.org/wiki/Tutorial:Hamster_Ball
http://love2d.org/wiki/Tutorial:Callback_Functions (at minimum look over love.load, love.update, and love.draw)
If you can do hamster ball and understand what is going on, getting a jump working would probably be next.
http://love2d.org/wiki/Tutorial:Hamster_Ball
http://love2d.org/wiki/Tutorial:Callback_Functions (at minimum look over love.load, love.update, and love.draw)
If you can do hamster ball and understand what is going on, getting a jump working would probably be next.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Next step is: make your character move left and right when you press keys left and right on the keyboard.toaster468 wrote:WOO! It works thanks a bunch guys!
Alright now onto the rest of my lesson, what is the next step?
In order to do that, you will have to:
- Start by storing the x coordinate of your character on a variable. Call it player_x. You can initialize it inside love.load.
- Use love.keypressed to increment/decrement the player_x
- Use the player_x variable to draw your character instead of having a fixed x.
Don't try do do animations yet.
When I write def I mean function.
Re: jumping tutorial?
I'll write a simple example... Nah. I'll write half a game.
Code: Select all
local player={} --where we put our variables
player.x=0
player.y=0
player.vx=0
player.vy=0
player.img=love.graphics.newImage("myPlayer.png") --player image
camerax=0 --scrolling!
cameray=0
lastjump=0 --when they last jumped
objects={}
for i=1,20 do --populate with bricks
table.insert(objects,{
x=i,y=0
})
end
function boxCollide(x1,y1,w1,h1, x2,y2,w2,h2) --this could easily be revised to check where they're intercepting.
local h,v=false,false --collision variables
if x2>x1 and x2<x1+w1 then --collision on x
h=true
end
if y2>y1 and y2<y1+h1 then
v=true
end
x2,y2=x2+w2,y2+h2
if x2>x1 and x2<x1+w1 then --collision on x
h=true
end
if y2>y1 and y2<y1+h1 then
v=true
end
return h,v --send them back to caller
end
function love.load() --stuff
end
function love.update(dt) --update player
player.x=player.x+player.vx --add velocity
player.y=player.y+player.vy
player.vy=player.vy-.3*dt --add coefficient of gravity
px,py=player.x,player.y
pw,ph=1,2 --we're multiplying by 16, so our player is 16x32
local h,v
for i=1,#objects do
local lh,lv=boxCollide(objects[i].x,objects[i].y,1,1, px,py,pw,ph) --check between box and player
h=h or lh --if h is false (nil), h=true
v=v or lv --if v is false (nil), v=true
end
if love.keyboard.isDown("left") then
player.vx=-1 --move left
end
if love.keyboard.isDown("right") then
player.vx=1 --move right
end
if h then --they slammed into a wall
player.vx=0
end
if v then --they slammed into the floor or ceiling
player.vy=0
end
end
function love.draw()
love.graphics.setBackgroundColor(0x00,0x00,0xff) --#0000ff = blue
love.graphics.setColor(0xff,0xff,0xff) --#ffffff = white
love.graphics.translate(-camerax,-cameray) --subtracts camera's pos automatically
love.graphics.scale(16,16) --make everything scaled 16x
love.graphics.draw(player.img,player.x,player.y) --draw our player
for i=1,#objects do
love.graphics.rectangle(objects[i].x,objects[i].y,1,1) --draw a 1x1 (16x16) box at x,y
end
end
function love.keypressed(k) --when someone presses a key
if k==" " and love.timer.getTime()-lastjumped<1 then --spacebar was pressed and player jumped more than 1 second ago
player.vy=player.vy+10 --superhuman jump!
lastjump=love.timer.getTime()
end
end
Hello, I am not dead.
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 0 guests