Followed the Physics tutorial, but nothing shows up
Posted: Wed Aug 22, 2018 3:10 am
The issue is that when I start the game (from the .love file, and the main.lua in ZeroBrane Studio), nothing shows and it's just a black screen: http://prntscr.com/klgj4h
Here is an image of what my project is supposed to look like: https://love2d.org/wiki/File:Tutorial-PhysicsBall.jpg
Here's my .love: Here's the code:
Here is an image of what my project is supposed to look like: https://love2d.org/wiki/File:Tutorial-PhysicsBall.jpg
Here's my .love: Here's the code:
Code: Select all
----Functions
function love.load()
love.physics.setMeter(100)
world = love.physics.newWorld(0, 9.81*100, false)
objects = {}
---Ground
objects.ground = {}
objects.ground.body = love.physics.newBody(world, 650/2, 650-50/2, "static")
objects.ground.shape = love.physics.newRectangleShape(429, 40)
objects.ground.fixture = love.physics.newFixture(objects.ground.body, objects.ground.shape)
---Ball
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic")
objects.ball.shape = love.physics.newCircleShape(20)
objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1)
objects.ball.fixture:setRestitution(0.9)
---Things to play with
objects.block1 = {}
objects.block1.body = love.physics.newBody(world, 200, 550, "dynamic")
objects.block1.shape = love.physics.newRectangleShape(0, 0, 50, 100)
objects.block1.fixture = love.physics.newFixture(objects.block1.body, objects.block1.shape, 5)
objects.block2 = {}
objects.block2.body = love.physics.newBody(world, 200, 400, "dynamic")
objects.block2.shape = love.physics.newRectangleShape(0, 0, 100, 50)
objects.block2.fixture = love.physics.newFixture(objects.block2.body, objects.block2.shape, 2)
---graphics stuff
love.graphics.setBackgroundColor(0.41,0.53,0.97)
love.window.setMode(650, 650)
end
function love.update(dt)
world:update(dt)
----Movement
if love.keyboard.isDown("a") then ---Left
objects.ball.body:applyForce(400, 0)
end
if love.keyboard.isDown("d") then ---Right
objects.ball.body:applyForce(-400, 0)
end
if love.keyboard.isDown(" ") then ---Up
objects.ball.body:setPosition(650/2, 650/2)
objects.ball.body:setLinearVelocity(0, 0)
end
end
function love.draw()
print("drawing")
love.graphics.setColor(0.28, 0.63, 0.05)
love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints()))
love.graphics.setColor(0.76, 0.18, 0.05)
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
love.graphics.setColor(0.20, 0.20, 0.20)
love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block2.shape:getPoints()))
love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
end