Socket
Socket
Sign inDemoInstall

tmx-parser-typescript

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tmx-parser-typescript

parse and load tiled maps


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
117 kB
Created
Weekly downloads
 

Readme

Source

tmx parser

Tiled Map Editor map parser made to work in node.js or browserify.

Usage

var tmx = require('tmx-parser');

// if you have a string (pathToFile is for resolving tilesets if necessary)
tmx.parse(xmlString, pathToFile, function(err, map) {
  if (err) throw err;
  console.log(map);
});

// if you have a file
tmx.parseFile(filename, function(err, map) {
  if (err) throw err;
  console.log(map);
});

The second example in that list uses tmx.readFile(filename, callback) and then calls tmx.parse(...) on the results. So if you're in browserland, you can replace the readFile function with your own asset loading function.

Documentation

A parsed map looks something like this:

{ version: '1.0',
  orientation: 'orthogonal',
  width: 200,
  height: 100,
  tileWidth: 16,
  tileHeight: 16,
  backgroundColor: undefined,
  layers: 
   [ { map: [Object],
       type: 'tile',
       name: 'Tiles',
       opacity: 1,
       visible: true,
       properties: {},
       tiles: [Object],
       horizontalFlips: [Object],
       verticalFlips: [Object],
       diagonalFlips: [Object] },
     { map: [Object],
       type: 'tile',
       name: 'Ladders',
       opacity: 1,
       visible: true,
       properties: {},
       tiles: [Object],
       horizontalFlips: [Object],
       verticalFlips: [Object],
       diagonalFlips: [Object] },
     { type: 'object',
       name: 'Objects',
       color: undefined,
       opacity: 1,
       visible: true,
       properties: {},
       objects: [Object] },
     { type: 'object',
       name: 'PlayerLayer',
       color: undefined,
       opacity: 1,
       visible: true,
       properties: {},
       objects: [] } ],
  properties: 
   { bg_art: 'background.png',
     bg_music: 'music/silly.mp3',
     fg_art: 'hill.png' },
  tileSets: 
   [ { firstGid: 1,
       source: 'tiles.tsx',
       name: 'default',
       tileWidth: 16,
       tileHeight: 16,
       spacing: null,
       margin: null,
       tileOffset: [Object],
       properties: {},
       image: [Object],
       tiles: [Object],
       terrainTypes: [] } ] }

The objects array looks like this:

{ type: 'object',
  name: 'Objects',
  color: undefined,
  opacity: 1,
  visible: true,
  properties: {},
  objects: 
   [ { name: undefined,
       type: 'Decoration',
       x: 0,
       y: 640,
       width: 224,
       height: 240,
       rotation: 0,
       properties: [Object],
       gid: null,
       visible: true,
       ellipse: false,
       polygon: null,
       polyline: null },
     { name: 'movement text',
       type: 'Text',
       x: 240,
       y: 640,
       width: 336,
       height: 80,
       rotation: 0,
       properties: [Object],
       gid: null,
       visible: true,
       ellipse: false,
       polygon: null,
       polyline: null },
     { name: 'victory',
       type: 'Victory',
       x: 2976,
       y: 880,
       width: 224,
       height: 96,
       rotation: 0,
       properties: {},
       gid: null,
       visible: true,
       ellipse: false,
       polygon: null,
       polyline: null } ] }

TileLayer objects have a tileAt(x, y) method. Otherwise you can access layer.tiles in row-major order.

See the bottom of index.js for more information.

FAQs

Last updated on 21 Sep 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc