forked from ponywolf/ponytiled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
44 lines (32 loc) · 1.69 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- This is a little demo project using the assets from
-- Sticker Knight https://github.com/coronalabs/Sticker-Knight-Platformer
-- and Generic Platform Tiles by surt http://opengameart.org/content/generic-platformer-tiles
-- The goal is to show basic map loading for object & tile based
-- maps via JSON or lua
local tiled = require "com.ponywolf.ponytiled"
local physics = require "physics"
local json = require "json"
-- if you use physics bodies in your map, you must
-- start() physics before you load your map
physics.start()
-- Demo 1
-- Load a "pixel perfect" map from a JSON export
display.setDefault("magTextureFilter", "nearest")
display.setDefault("minTextureFilter", "nearest")
local mapData = json.decodeFile(system.pathForFile("maps/tiles/tilemap.json", system.ResourceDirectory)) -- load from json export
local map = tiled.new(mapData, "maps/tiles")
-- Demo 2
-- Load an object based map from a JSON file
--local mapData = json.decodeFile(system.pathForFile("maps/objects/sandbox.json", system.ResourceDirectory)) -- load from json export
--local map = tiled.new(mapData, "maps/objects")
-- Demo 3
-- Load a "pixel perfect" map from a JSON export w/ External tileset
--display.setDefault("magTextureFilter", "nearest")
--display.setDefault("minTextureFilter", "nearest")
--local mapData = json.decodeFile(system.pathForFile("maps/external/outdoor.json", system.ResourceDirectory)) -- load from json export
--local map = tiled.new(mapData, "maps/external")
-- center the map on screen
map.x,map.y = display.contentCenterX - map.designedWidth/2, display.contentCenterY - map.designedHeight/2
-- drag the whole map for fun
local dragable = require "com.ponywolf.plugins.dragable"
map = dragable.new(map)