背景图像重叠字符(love2d)
Background image overlapping character (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
首先让我开始吧,我知道这是很多代码,所以很抱歉。我试图让一个角色以其背后的图像作为背景移动。当我 运行 程序时,似乎发生的是背景与字符重叠,你看不到字符。当我删除背景代码时,角色会出现并正常工作。谁能告诉我我做错了什么?
非常感谢
重新排列 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
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
首先让我开始吧,我知道这是很多代码,所以很抱歉。我试图让一个角色以其背后的图像作为背景移动。当我 运行 程序时,似乎发生的是背景与字符重叠,你看不到字符。当我删除背景代码时,角色会出现并正常工作。谁能告诉我我做错了什么? 非常感谢
重新排列 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