Lua在游戏中获得玩家的(x,y)
我想实时找到我的玩家的x和y坐标,这样我就知道在哪里进行下一个级别的游戏。我目前正在使用LÖVE 2D来运行我的代码。当我试图打印出Lua在游戏中获得玩家的(x,y),lua,love2d,Lua,Love2d,我想实时找到我的玩家的x和y坐标,这样我就知道在哪里进行下一个级别的游戏。我目前正在使用LÖVE 2D来运行我的代码。当我试图打印出player.x和player.y时,游戏运行正常,但没有坐标的文本输出。我试图改变文本所在的位置,但这不起作用。感谢您的帮助。注意:我今天刚开始学习Lua,请直截了当地说。) love.graphics.setDefaultFilter('nearest','nearest') 函数love.load() room1Image=love.graphics.newI
player.x
和player.y
时,游戏运行正常,但没有坐标的文本输出。我试图改变文本所在的位置,但这不起作用。感谢您的帮助。注意:我今天刚开始学习Lua,请直截了当地说。)
love.graphics.setDefaultFilter('nearest','nearest')
函数love.load()
room1Image=love.graphics.newImage('room1.png'))
room2Image=love.graphics.newImage('room2.png')
room3Image=love.graphics.newImage('room3.png')
房间1=真
房间2=假
房间3=假
玩家={}
player.x=0
player.y=255
player.speed=5
player.image=love.graphics.newImage('player.png')
结束
函数love.update(dt)
如果love.keyboard.isDown(“左”),那么
player.x=player.x-5
结束
如果love.keyboard.isDown(“右”),那么
player.x=player.x+5
结束
如果爱.键盘.isDown(“up”)那么
player.y=player.y-5
结束
如果love.keyboard.isDown(“down”)那么
player.y=player.y+5
结束
如果player.y>=600且房间为1,则
房间1=假
房间2=正确
player.y=5
结束
如果player.y=600且房间为2,则
房间2=假
房间3=正确
player.y=5
结束
如果player.y如果要向控制台输出内容,请使用print()
。这将在游戏窗口中不可见
如果您想在游戏中向玩家显示一些文本,请调用love.graphics.print
insidelove.draw()
:
我看不到有人试图在你的代码中打印坐标。谢谢!感谢您的回复:)
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
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