Question and problem: How do you put in a .png image?
Posted: Wed Mar 14, 2012 10:14 pm
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!
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!