Followed the Physics tutorial, but nothing shows up

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
amkdux
Prole
Posts: 1
Joined: Wed Aug 22, 2018 2:56 am

Followed the Physics tutorial, but nothing shows up

Post by amkdux »

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:
test.love
(805 Bytes) Downloaded 102 times
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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Followed the Physics tutorial, but nothing shows up

Post by grump »

You're running this with LÖVE < 11 with color values that only work in 11. Remove/replace the setColor lines and something will show up.
User avatar
pgimeno
Party member
Posts: 3684
Joined: Sun Oct 18, 2015 2:58 pm

Re: Followed the Physics tutorial, but nothing shows up

Post by pgimeno »

Or upgrade to 11 ;)
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 4 guests