function love.load()
fruits={}
end
function love.load()
--每个值用逗号分隔,就像参数和自变量一样
-- Each value is separated by a comma, just like with parameters and arguments
fruits={"apple","banana"}
end
function love.load()
--每个值用逗号分隔,就像参数和自变量一样
--Each value is separated by a comma, just like with parameters and arguments
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
love.graphics.print("Test",100,100)
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
--love.graphics.print("Test",100,100)
love.graphics.print(fruits[1],100,100)
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
--love.graphics.print("Test",100,100)
--love.graphics.print(fruits[1],100,100)function love.draw()
love.graphics.print(fruits[1], 100, 100)
love.graphics.print(fruits[2], 100, 200)
love.graphics.print(fruits[3], 100, 300)
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
for i=1,10
do
love.graphics.print("hello",100,i*50)
end
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
-- for i=1,10
-- do
-- love.graphics.print("hello",100,i*50)
-- end
for i=1,3
do
love.graphics.print(fruits[i],100,i*50)
end
end
function love.load()
fruits = {"apple", "banana"}
print(#fruits)
--Output: 2
table.insert(fruits, "pear")
print(#fruits)
--Output: 3
for i=1,#fruits do
print(fruits[i])
end
end
function love.load()
fruits={"apple","banana"}
--table.insert(fruits,"pear")
end
function love.update(dt)
end
function love.draw()
love.graphics.print(#fruits,100,100)
end
function love.load()
fruits = {"apple", "banana"}
print(#fruits)
--Output: 2
table.insert(fruits, "pear")
print(#fruits)
--Output: 3
for i=1,#fruits do
print(fruits[i])
end
end
function love.update()
end
function love.draw()
for i=1,#fruits
do
love.graphics.print(fruits[i], 100, 100)
end
end
print(#fruits)
–Output: 2
table.insert(fruits, “pear”)
print(#fruits)
–Output: 3
for i=1,#fruits do
print(fruits[i])
end
end
function love.update()
end
function love.draw()
for i=1,#fruits
do
love.graphics.print(fruits[i], 100, i*100)
end
end`
function love.load()
fruits = {"apple", "banana"}
print(#fruits)
--Output: 2
table.insert(fruits, "pear")
print(#fruits)
--Output: 3
table.insert(fruits,"pineapple")
for i=1,#fruits do
print(fruits[i])
end
end
function love.update()
end
function love.draw()
for i=1,#fruits
do
love.graphics.print(fruits[i], 100, i*100)
end
end
function love.load()
fruits = {"apple", "banana"}
print(#fruits)
--Output: 2
table.insert(fruits, "pear")
print(#fruits)
--Output: 3
table.insert(fruits,"pineapple")
table.remove(fruits,2)
for i=1,#fruits do
print(fruits[i])
end
end
function love.update()
end
function love.draw()
for i=1,#fruits
do
love.graphics.print(fruits[i], 100, i*100)
end
end
function love.load()
fruits = {"apple", "banana"}
print(#fruits)
--Output: 2
table.insert(fruits, "pear")
print(#fruits)
--Output: 3
table.insert(fruits,"pineapple")
table.remove(fruits,2)
fruits[1] = "tomato"
for i=1,#fruits do
print(fruits[i])
end
end
function love.update()
end
function love.draw()
for i=1,#fruits
do
love.graphics.print(fruits[i], 100, i*100)
end
end
function love.load()
fruits={"apple","banana"}
table.insert(fruits,"pear")
table.insert(fruits,"pineapple")
table.remove(fruits,2)
fruits[1]="tomato"
end
function love.update(dt)
end
function love.draw()
for k,v in ipairs(fruits)
do
love.graphics.print(k,100,50*k)
love.graphics.print(v,200+k*5,50*k)
end
end
for i=1, #fruits do
v = fruits[i]
end
function love.draw()
-- i和v是变量,所以我们可以随意命名
for i,frt in ipairs(fruits)
do
love.graphics.print(frt, 100, 100 + 50 * i)
end
end
以上就是今天要讲的内容,本文仅仅简单介绍了Love2d之表格(tables)和for循环(for-loops)的使用,介绍了love2d的三个主要函数扩展办法,与博主的lua语言文章结合更好的理解love2d的编码,如果你是一名独立游戏开发者,或者一位对游戏开发有着深厚兴趣,但是又对于unity3d,ue4等这些对于新手而言不太友好的引擎而头疼的开发者;那么现在,你可以试试Love2D。Love2D是一款基于Lua编写的轻量级游戏框架,尽管官方称呼其为引擎,但实际上它只能称得上是一个框架,因为他并没有一套全面完整的解决方案。不过,这款框架上手及其容易,是学习游戏开发的初学者入门的一个良好选择。
创作打卡挑战赛
赢取流量/现金/CSDN周边激励大奖
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/qq_44918090/article/details/124399223
内容来源于网络,如有侵权,请联系作者删除!