Page 1 of 1

Question and problem: How do you put in a .png image?

Posted: Wed Mar 14, 2012 10:14 pm
by qwetroop
I have tried, but it does not work for me, i am EXTREMELY new to LOVE and i only know the basics of lua programming. So, what i did was i took the a couple tutorials on the wiki, and one of them was the physics one, and to test out how our character will look in the actual game, i put the callback command for making the .png image into the ball. This is the exact script:
function love.load()
world = love.physics.newWorld(0, 0, 650, 650)
world:setMeter(64)
objects = {}
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 650/2, 625, 0, 0)
objects.ground.shape = love.physics.newRectangleShape(objects.ground.body, 0, 0, 650, 50, 0)
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, 15, 0)
objects.ball.shape = love.physics.newCircleShape(objects.ball.body, 0, 0, 20)
love.graphics.setBackgroundColor(104, 136, 248)
love.graphics.setMode(650, 650, false, true, 0)
end
function love.update(dt)
world:update(dt)
if love.keyboard.isDown("right") then
objects.ball.body:applyForce(400, 0)
elseif love.keyboard.isDown("left") then
objects.ball.body:applyForce(-400, 0)
elseif love.keyboard.isDown("up") then
objects.ball.body:setY(650/2)
end
end
function love.draw()
love.graphics.setColor(72, 160, 14)
love.graphics.polygon("fill", objects.ground.shape:getPoints())

love.graphics.setColor(193, 47, 14)
love.graphics.circle(objects.ball.body:function love.load()
image = love.graphics.newImage("template.png")
local f = love.graphics.newFont(12)
love.graphics.setFont(f)
love.graphics.setColor(0,0,0,255)
love.graphics.setBackgroundColor(255,255,255)
end)
end
When i put the folder into love, it gives me this error:
<name> Expected near function on line 29
Please help and correct me, and thank you in advance!

Re: Question and problem: How do you put in a .png image?

Posted: Wed Mar 14, 2012 10:26 pm
by jradich
The problem is that I don't think you can load new variables like you are trying to do. Could you please provide a .love?


EDIT: And also, instead of using physics, you should just do something like:

Code: Select all

function love.load()
  guy=love.graphics.newImage('template.png')
  guyx=20
  guyy=20
  guyspeed=20
end
function love.update(dt)
  if guyy<500 then--"gravity"
    guyy=guyy-2
  end
end
function love.draw()
  love.graphics.draw(guy,guyx,guyy)
end
That should be all you need.

Re: Question and problem: How do you put in a .png image?

Posted: Wed Mar 14, 2012 10:30 pm
by nevon
This part is completely messed up. I don't even know what's going on.

Code: Select all

function love.draw()
	love.graphics.setColor(72, 160, 14) 
	love.graphics.polygon("fill", objects.ground.shape:getPoints())

	love.graphics.setColor(193, 47, 14) 
	love.graphics.circle(objects.ball.body:function love.load()
	image = love.graphics.newImage("template.png")
	local f = love.graphics.newFont(12)
	love.graphics.setFont(f)
	love.graphics.setColor(0,0,0,255)
	love.graphics.setBackgroundColor(255,255,255)
	end)
end

Re: Question and problem: How do you put in a .png image?

Posted: Wed Mar 14, 2012 10:33 pm
by jradich
dear qwetroop,
check ma edit.
love,
jradich

Re: Question and problem: How do you put in a .png image?

Posted: Wed Mar 14, 2012 10:57 pm
by Jasoco
Oh, and for the future, please use the Code tags. It makes your post actually readable and preserves spaces and tabulation.

Code: Select all

function awesome()
  print("Radical!")
end

Re: Question and problem: How do you put in a .png image?

Posted: Thu Mar 15, 2012 8:10 pm
by qwetroop
Well, for the edit, his gravity is backwards xD but yeah, that works! thank you! and from now on, i will do the code tags, thanks!