GithubHelp home page GithubHelp logo

brandonyuen / pixi-tiledmap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from riebel/pixi-tiledmap

0.0 1.0 0.0 2.02 MB

Pixi.js Tiled map editor plugin

License: MIT License

HTML 8.93% JavaScript 91.07%

pixi-tiledmap's Introduction

pixi-tiledmap NPM version

Use Tiled Map Editor maps with pixi.js.

pixi-tiledmap is a Pixi loader middleware which loads Tiled Map Editor TMX maps and parses them with node-tmx-parser. It exports a pixi.js class PIXI.extras.TiledMap which is an extended PIXI.Container containing all layers of the tile map as an instance of PIXI.Container and all tiles within as an instance of PIXI.extras.AnimatedSprite.

Installation

npm install pixi-tiledmap

or

yarn add pixi-tiledmap

or include pixi-tiledmap.min.js after pixi.js in your html file (See example/browser for an example).

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>pixi-tiledmap example</title>
</head>
<body>
<script type="text/javascript" src="https://pixijs.download/v4.6.2/pixi.min.js"></script>
<script type="text/javascript" src="pixi-tiledmap.min.js"></script>
<script>
    var renderer = PIXI.autoDetectRenderer(442, 286);
    document.body.appendChild(renderer.view);

    /**
     * Simply load a Tiled map in TMX format like a usual resource
     */
    PIXI.loader
        .add('assets/01_basement.tmx')
        .load(function () {
                /**
                 *   PIXI.extras.TiledMap() is an extended PIXI.Container()
                 *   so you can render it right away
                 */
                var tileMap = new PIXI.extras.TiledMap('assets/01_basement.tmx');
                renderer.render(tileMap);
            }
        );
</script>
</body>
</html>

Usage

var PIXI = require('pixi.js');
require('pixi-tiledmap');

var renderer = PIXI.autoDetectRenderer(1024, 768);
document.body.appendChild(renderer.view);

/**
 * Simply load a Tiled map in TMX format like a usual resource
 */
PIXI.loader
    .add('map.tmx')
    .load( function () {
        /**
        *   PIXI.extras.TiledMap() is an extended PIXI.Container()
        *   so you can render it right away
        */
        renderer.render(new PIXI.extras.TiledMap("map.tmx"));
    }
    /**
        //Alternatively, an alias can be used in order to identify loaded map.
         
        .add("myMap", "path/to/myMap.tmx")
        .load( function () {
              renderer.render(new PIXI.extras.TiledMap("myMap"));
        }
    */
);

ES6

import * as PIXI from 'pixi.js';
import 'pixi-tiledmap';

const renderer = PIXI.autoDetectRenderer(442, 286);
document.body.appendChild(renderer.view);

/**
 * Simply load a Tiled map in TMX format like a usual resource
 */
PIXI.loader
    .add('assets/01_basement.tmx')
    .load(() => {
        /**
         *   PIXI.extras.TiledMap() is an extended PIXI.Container()
         *   so you can render it right away
         */
        renderer.render(new PIXI.extras.TiledMap('assets/01_basement.tmx'));
    });

An example implementation with webpack can be found under example/webpack.

For the browser example run npm install and npm run example to start a http-server on Port 8080. Open http://localhost:8080/ in your browser.

Documentation

Example TiledMap object

{
    alpha: 1
    backgroundColor: undefined
    cacheAsBitmap: (...)
    children: Array[3]
        0: ImageLayer
            alpha: 1
            cacheAsBitmap: (...)
            children: Array[1]
            filterArea: null
            filters: (...)
            height: (...)
            image: Image
            mask: (...)
            name: "background"
            opacity: 1
            parent: TiledMap
            pivot: Point
            position: Point
            properties: Object
            renderable: true
            rotation: 0
            scale: Point
            type: "image"
            visible: true
            width: (...)
            worldAlpha: 1
            worldTransform: Matrix
            worldVisible: (...)
            x: (...)
            y: (...)
        1: TileLayer
        2: TileLayer
            alpha: 1
            cacheAsBitmap: (...)
            children: Array[4]
            diagonalFlips: Array[187]
            filterArea: null
            filters: (...)
            height: (...)
            horizontalFlips: Array[187]
            map: Map
            mask: null
            name: "fire"
            opacity: 1
            parent: TiledMap
            pivot: Point
            position: Point
            properties: Object
            renderable: true
            rotation: 0
            scale: Point
            tiles: Array[4]
                0: Tile
                    alpha: 1
                    anchor: Point
                    animation: undefined
                    animationSpeed: 0.16666666666666669
                    animations: Array[6]
                    blendMode: 0
                    cacheAsBitmap: (...)
                    cachedTint: 16777215
                    children: Array[0]
                    currentFrame: (...)
                    filterArea: null
                    filters: (...)
                    gid: 33
                    height: (...)
                    id: 0
                    image: null
                    loop: true
                    mask: (...)
                    onComplete: null
                    parent: TileLayer
                    pivot: Point
                    playing: true
                    position: Point
                    probability: null
                    properties: Object
                    renderable: true
                    rotation: 0
                    scale: Point
                    shader: null
                    terrain: Array[0]
                    texture: (...)
                    textures: (...)
                    tint: 16777215
                    totalFrames: (...)
                    visible: true
                    width: (...)
                    worldAlpha: 1
                    worldTransform: Matrix
                    worldVisible: (...)
                    x: (...)
                    y: (...)
                1: Tile
                2: Tile
                3: Tile
            type: "tile"
            verticalFlips: Array[187]
            visible: true
            width: (...)
            worldAlpha: 1
            worldTransform: Matrix
            worldVisible: (...)
            x: (...)
            y: (...)
    filterArea: null
    filters: (...)
    height: (...)
    layers: Array[0]
    mask: (...)
    orientation: "orthogonal"
    parent: Container
    pivot: Point
    position: Point
    properties: Object
    renderable: true
    rotation: 0
    scale: Point
    tileHeight: 26
    tileSets: Array[2]
    tileWidth: 26
    version: "1.0"
    visible: true
    width: (...)
    worldAlpha: 1
    worldTransform: Matrix
    worldVisible: (...)
    x: (...)
    y: (...)
}

To do

support isometric and hexagonal orientation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.