add tilemap

This commit is contained in:
Fabien Freling 2025-02-28 14:05:37 +01:00
parent e4d98b7fed
commit f92e88b554
3 changed files with 8 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

BIN
src/img/tilemap.pxo Normal file

Binary file not shown.

View file

@ -1,37 +1,19 @@
-- Name this file `main.lua`. Your game can use multiple source files if you wish
-- (use the `import "myFilename"` command), but the simplest games can be written
-- with just `main.lua`.
-- You'll want to import these in just about every project you'll work on.
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
-- Declaring this "gfx" shorthand will make your life easier. Instead of having
-- to preface all graphics calls with "playdate.graphics", just use "gfx."
-- Performance will be slightly enhanced, too.
-- NOTE: Because it's local, you'll have to do it in every .lua source file.
local gfx <const> = playdate.graphics
-- Here's our player sprite declaration. We'll scope it to this file because
-- several functions need to access it.
local playerSprite = nil
-- A function to set up our game environment.
function myGameSetUp()
-- Set up the player sprite.
local playerImage = gfx.image.new("img/player.png")
assert(playerImage) -- make sure the image was where we thought
assert(playerImage)
playerSprite = gfx.sprite.new(playerImage)
playerSprite:moveTo(200, 120) -- this is where the center of the sprite is placed; (200,120) is the center of the Playdate screen
playerSprite:add() -- This is critical!
playerSprite:moveTo(200, 120) -- (200,120) is the center of the Playdate screen
playerSprite:add()
-- We want an environment displayed behind our sprite.
-- There are generally two ways to do this:
@ -50,6 +32,11 @@ function myGameSetUp()
-- backgroundImage:draw(0, 0)
-- end
-- )
local table = gfx.imagetable.new("img/tilemap-table-16-16.png")
local map = gfx.tilemap.new()
map:setImageTable(table)
map:draw(0, 0)
end
-- Now we'll call the function above to configure our game.