Giter Site home page Giter Site logo

ponytiled's Introduction

ponytiled

ponytiled is a simple Tiled Map Loader for Corona SDK

Screenshot of ponytiled in action

In 350 lines of code, ponytiled loads a sub-set of Tiled layers, tilesets and image collections. Built in plugin hooks and extensions make it easy to add support for many custom object types.

  • Loads .LUA + .JSON exports from www.mapeditor.org
  • Adds basic properties from tiled including physics
  • Supports object layers and tile layers
  • Supports collections of images and tileset images
  • Supports object x/y flipping and re-centering of anchorX/anchorY for Corona
  • Particle plugin
  • Rectangle shape with fillColor and strokeColor support
  • Polygon import with physics support for edge chains

Quick Start Guide

tiled = require "com.ponywolf.ponytiled"
map = tiled.new( data, dir )

data

Data is a lua table that contains an export of the tiled map in either .lua or .json format. The easiest way to populate that table is to export a map from Tiled in .lua format and require it in your code.

Lua export via Tiled

local mapData = require "sandbox" -- load from lua export
local map = tiled.new(mapData)

dir

Most of the time you will store you maps and images/tilesets in a directory. The dir parameter overides where ponytiled looks for images.

local mapData = require "maps.objects.sandbox" -- load from lua export
local map = tiled.new(mapData, "maps/objects") -- look for images in /maps/objects/

map

ponytiled returns a map display object that contains all the layers, objects and tiles for the exported map. (0,0) is the designed upper left hand corner of the map. Objects may be above or to the left of the origin or beyond the designed width and height.

map display objects have all the same properties of a normal display group.

map.xScale = 2
map.alpha = 0.5
map:translate(-30,30)

map.designedWidth and map.designedHeight are the width and height of you map as specified in tiled's new map options. map objects also have functions to make it easy to find image objects to manipulate them with code.

map:findObject(name)

This funtion will return the first display object with the name specified. Great for getting to the display object of a unique item in the map.

Setting a hero name

myHero = map:findObject("hero")
myHero:toFront()
myHero:rotate(45)

map:listTypes(types)

To find multiple objects, use map:listTypes(). This will return a table of display objects matching the type specified. Setting a "coin" type

myCoins = map:listTypes( "coin" )
print("Number of coins in map", #myCoins)
display.remove(myCoins[1])

map:findLayer(name)

To find a layer (which itself is a nested display group), use map:findLayer().

myLayer = map:findLayer( "hud" )
myLayer.alpha = 0.5

Extensions

map:extend(types)

The extend() function attaches a lua code module to a image object. You can use this to build custom classes in your game.

There are code examples of this in the "com/ponywolf/plugins" folder.

Custom Properties

The most exciting part of working in Tiled & Corona is the idea of custom properites. You can select any image object on any object layer in tiled and add any number of custom properties. ponytiled will apply those properties to the image object as it loads. This allows you to put physics properties, custom draw modes, user data, etc. on an in-game item via the editor.

Setting a bodyType object

bodyType

One special custom property is bodyType. This triggers ponytiled to add a physics body to an object and pass the rest of the custom properties as physics options. Rectangle bodies are currently supported by default, adding a radius property will give you a round body.

ponytiled's People

Contributors

superqix avatar

Watchers

James Cloos avatar 0x55aa avatar

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.