berry is a simple Tiled Map Loader for Corona SDK.
berry supports only part of functionality offered to user by Tiled. This includes tile and object layers, tilesets and collections of images. Neverthless it can be extended by using custom properties and executing custom code to gain more flexibility and control.
- Loads .JSON export 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
- Supports object animations using Corona sequences
- Rectangle shape with fillColor and strokeColor support
- Supports custom collision shapes. Only rectangles and polygons for now
- Supports Text object
berry = require( 'pl.ldurniat.berry' )
local map = berry.loadMap( filename, tileSetsDirectory )
local visual = berry.createVisual( map )
berry.buildPhysical( map )
The filename specify path to file with map.
Most of the time you will store you maps and images/tilesets in a directory. The tileSetsDirectory parameter overides where berry looks for images.
local map = berry.loadMap( 'scene/game/map/sandbox.json', 'scene/game/map' ) -- look for images in /scene/game/map/
The map object exposes methods to manipulate adn find layers, objects and tiles. See documentation for more information.
map.designedWidth and map.designedHeight are the width and height of your map as specified in tiled's new map options. The map will be centered on the screen by default.
berry returns a group object that contains all the layers, objects and tiles for the exported map.
The extendObjects() function attaches a lua code module to a image object. You can use this to build custom classes in your game.
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. berry 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.
Note: Tile properties will not be inherited by objects so you have to add it to objects itself with the exception of animation properties.
One special custom property is hasBody. This triggers berry to add a physics body to an object/tile 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. More complicated shape you can obtain by using the Collision Editor. No all shapes are supported.
One more special property you may want to use is isAnimated. This triggers berry to replace simple image object with animation created in Tiled using the Animation Editor.
To gain some useful information about what is going on use berry:enableDebugMode()
and berry:enableDebugMode()
methods. If debug mode is enabled berry print out simple messages what he is doing. Use berry:isDebugModeEnabled()
to check if debug mode is currently enabled or disabled.
See Sticker-Knight-Platformer and wiki.
- Support for isometric maps
- Support for hex maps
- Collision filter
- Parallax effect
- Camera effect
- Support for external tilesets
- Support for custom object types
- Support for multi-element bodies
If you think that any information you obtained here is worth of some money and are willing to pay for it, feel free to send any amount through paypal. Thanks :)
If you have any idea, feel free to fork it and submit your changes back to me.
This project is licensed under the MIT License - see the LICENSE.md file for details.