Page 1 of 1

Black screen on start

Posted: Sun Mar 22, 2020 11:19 pm
by Nerdzmasterz
Hi, there!

I honestly don't know what I did. Things were great until I decided to use HUMP's camera to adjust the camera for only one scene, not both of them. Here is the main.lua file. The player code only has the images of the player and its X and Y position, so it's unrelated.

Code: Select all

windowCenterX     = love.graphics.getWidth() / 2
windowCenterY     = love.graphics.getHeight() / 2
startButtonWidth  = 228
startButtonHeight = 34
startButtonStartX = windowCenterX - (startButtonWidth / 2)
startButtonStartY = windowCenterY - (startButtonHeight / 2)
startButtonEndX   = startButtonStartX + startButtonWidth
startButtonEndY   = startButtonStartY + startButtonHeight

level = 0

function love.load()
  
  require("Player")
  sti = require("Simple-Tiled-Implementation-master/sti")
  
  BrokenBridge = sti("maps/BrokenBridge.lua")
  
  themeSound = love.audio.newSource("sounds/mad_scientist.mp3", "static")
  themeSound:setLooping(true)
  themeSound:play()
  
  sprites = {}
  sprites.background1 = love.graphics.newImage("sprites/Background1_pc.png")
  
  sprites.startButton = love.graphics.newImage("sprites/button_Start_G.png")
  sprites.pressedStartButton = love.graphics.newImage("sprites/button_Start_R.png")
  
  cameraFile = require("hump-master/camera")
  
  cam = cameraFile()

  normalWorld = love.physics.newWorld(0, 100)
  
end


function love.update(dt)
  
  if level > 0 then
    BrokenBridge:update(dt)
    cam:lookAt(Player.x, Player.y)
  end
end



function love.draw()
  
  cam:attach()
  

  
  if level > 0 then
  love.graphics.draw(Player, StartX, StartY, nil, 0.25, 0.25)
end

  if level == 1 then    
     BrokenBridge:drawLayer(BrokenBridge.layers["Background"])
   end
   
   cam:detach()
   
  love.graphics.draw(sprites.background1, 0, 0)
  love.graphics.draw(sprites.startButton, startButtonStartX, startButtonStartY)
end



function isStartButtonClicked(mouseX, mouseY)
  if (mouseX > startButtonStartX) and (mouseX < startButtonEndX) and (mouseY > startButtonStartY) and (mouseY < startButtonEndY) and level == 0 then
    return true
  end
  return false
  
  
  
end

function love.mousepressed(mouseX, mouseY, button, istouch)
  if isStartButtonClicked(mouseX, mouseY) then
    level = 1
  end
end

function startLevel()
  
  for i,obj in pairs(BrokenBridge.layers["StartPosition"]) do
    StartX = obj.x
    StartY = obj.y
  end
  
end

Re: Black screen on start

Posted: Mon Mar 23, 2020 12:10 am
by papainoel14
in its main it is possible to notice that the game starts at level 0, however in the part of the draw it is noticed that only something is shown on the screen when the level is above 0, that is, until it goes out of 0 nothing will be shown.
If you want something to be shown as soon as you open the game you have to put draw at level 0.

I imagine that's it, I wait to see if it worked

Re: Black screen on start

Posted: Mon Mar 23, 2020 7:55 am
by Nerdzmasterz
Thanks for the tip! Still not working, though.