我想实时找到我的玩家的x和y坐标,所以我知道在哪里进行下一级游戏。我目前正在使用LÖVE2D来运行我的代码。当我尝试打印player.x
和player.y
时,游戏运行正常,但没有坐标的文本输出。我试图改变文本所在位置,但这不起作用。任何帮助表示赞赏。注意:我今天刚刚开始使用Lua,所以请直言不讳。 :)
love.graphics.setDefaultFilter('nearest','nearest')
function love.load()
room1Image = love.graphics.newImage('room1.png')
room2Image = love.graphics.newImage('room2.png')
room3Image = love.graphics.newImage('room3.png')
room1 = true
room2 = false
room3 = false
player = {}
player.x = 0
player.y = 255
player.speed = 5
player.image = love.graphics.newImage('player.png')
end
function love.update(dt)
if love.keyboard.isDown("left") then
player.x = player.x - 5
end
if love.keyboard.isDown("right") then
player.x = player.x + 5
end
if love.keyboard.isDown("up") then
player.y = player.y - 5
end
if love.keyboard.isDown("down") then
player.y = player.y + 5
end
if player.y >= 600 and room1 then
room1 = false
room2 = true
player.y = 5
end
if player.y <= 0 and room2 then
room1 = true
room2 = false
player.y = 600
end
if player.y >= 600 and room2 then
room2 = false
room3 = true
player.y = 5
end
if player.y <= 0 and room3 then
room2 = true
room3 = false
player.y = 600
end
end
function love.draw()
--draw background
if room1 then
love.graphics.draw(room1Image, room1Image.x, room1Image.y)
elseif room2 then
love.graphics.draw(room2Image, room2Image.x, room2Image.y)
elseif room3 then
love.graphics.draw(room3Image, room3Image.x, room3Image.y)
end
--draw player
love.graphics.draw(player.image, player.x, player.y, 0, 5)
end
答案 0 :(得分:1)
如果要将某些内容输出到控制台,请使用love.graphics.print
。这在游戏窗口中不可见。
如果您想向玩家展示一些文字(在游戏中),请在love.draw()
内拨打local x,y = 0, 0 --coordinates at which the text is printed
function love.load()
end
function love.update(dt)
end
function love.draw()
love.graphics.print("This is something I want you to see.", x, y)
end
:
{{1}}