背景图像重叠字符(love2d)

时间:2016-03-05 03:35:23

标签: background lua layer love2d

background = love.graphics.newImage ("joust.png")
  bird = love.graphics.newImage ("bird.png")
  x = 0
  y = 128
  speed = 300

  function love.update (dt)
    if love.keyboard.isDown ("d") then
      x = x + (speed * dt)
    end
    if love.keyboard.isDown ("a") then
      x = x - (speed * dt)
    end
    if love.keyboard.isDown ("w") then
      y = y - (speed * dt)
    end
    if love.keyboard.isDown ("s") then
      y = y + (speed * dt)
    end
  end

 function love.draw()
  love.graphics.draw(bird, x, y)
  for i = 0, love.graphics.getWidth() / background:getWidth() do
    for j = 0, love.graphics.getHeight() / background:getHeight() do
      love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
    end
  end
 end

首先我要知道这是很多代码所以我很抱歉。我试图让一个角色移动,背后的图像作为背景。当我运行程序时,似乎发生的事情是背景与角色重叠,你无法看到角色。当我删除背景代码时,角色出现并按预期工作。谁能告诉我我做错了什么? 非常感谢

1 个答案:

答案 0 :(得分:4)

重新排列love.draw()函数以在背景后绘制鸟:

 function love.draw()
  for i = 0, love.graphics.getWidth() / background:getWidth() do
    for j = 0, love.graphics.getHeight() / background:getHeight() do
      love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
    end
  end
  love.graphics.draw(bird, x, y)
 end