Love2D学习 - 代码2

function love.load()


map_width = 60
map_height = 40


map={}
--initialize the table
for i = 1,map_width do
map[i] = {}
for j = 1,map_height do
map[i][j] = math.random(0,3)
end
end


mapX = 1
mapY = 1


tileDisWidth = 26
tileDisHeight = 20




zoomX = 1
zoomY = 1


--construct map


tilesetImage = love.graphics.newImage( "/res/map.png" )
tilesetImage:setFilter("nearest", "linear") -- this "linear filter" removes some artifacts if we were to scale the tiles
tileSize = 32




-- grass
img1 = love.graphics.newQuad(0 * tileSize, 20 * tileSize, tileSize, tileSize,
tilesetImage:getWidth(), tilesetImage:getHeight())
-- kitchen floor tile
img2 = love.graphics.newQuad(2 * tileSize, 0 * tileSize, tileSize, tileSize,
tilesetImage:getWidth(), tilesetImage:getHeight())
-- parquet flooring
img3 = love.graphics.newQuad(4 * tileSize, 0 * tileSize, tileSize, tileSize,
tilesetImage:getWidth(), tilesetImage:getHeight())
-- middle of red carpet
img4 = love.graphics.newQuad(3 * tileSize, 9 * tileSize, tileSize, tileSize,
tilesetImage:getWidth(), tilesetImage:getHeight())


tilesetBatch = love.graphics.newSpriteBatch(tilesetImage, 600)


end


function updateTilesetBatch()
tilesetBatch:clear()


tilesetBatch:addq(img1, 32, 32)
tilesetBatch:addq(img2, 64, 64)
tilesetBatch:addq(img3, 128, 128)
tilesetBatch:addq(img4, 256, 256)


end


function love.draw()
  love.graphics.draw(tilesetBatch)
end
]]
--[[
img = love.graphics.newImage("/house/house1.png")


-- Let's say we want to display only the top-left
-- 32x32 quadrant of the Image:
top_left = love.graphics.newQuad(0, 0, img:getWidth(), img:getHeight(), img:getWidth(), img:getHeight())


-- And here is bottom left:
bottom_left = love.graphics.newQuad(200, img:getHeight()+20, img:getWidth(), img:getHeight(), img:getWidth(), img:getHeight())


--tilesetBatch = love.graphics.newSpriteBatch(img, 400)




--love.graphics.drawq(img, top_left, 200, 200)
--love.graphics.draw(tilesetBatch)


function love.draw()
    love.graphics.drawq(img, top_left, 50, 50)
    love.graphics.drawq(img, bottom_left, 100, 200)
end
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值