I’m doing my first tiled based map using Tiled and I’ve played around with both Berry and PonyTiled and managed to get both to load the map. However none of them are applying physics to any of my tiles.
I’ll write what I’m doing for both Berry and PonyTiled here:
In Tiled v. 1.2.4:
- Create a new map using CSV as the Tile Layer Format.
- Open a new tile set ‘based on tileset image’.
- Check the ‘embed in map’ option.
- In Tile Collision Editor I outline the collision box
- I add the following custom properties to both the tile itself and the collision box: hasBody = true (used for Berry), bodyType = static, bounce = 0.3, friction = 1.
- I export the map as .json for Berry and .lua for PonyTiled.
- I put the exported map along with my spritesheet in the root folder of my project.
In Corona, for Berry:
local physics = require( 'physics' ) berry = require( 'pl.ldurniat.berry' ) local json = require( "json" ) local sceneGroup = self.view physics.start() physics.setDrawMode("hybrid") local map = berry.loadMap( 'testmap\_embed.json' ) local visual = berry.createVisual( map ) berry.buildPhysical( map ) Ball = display.newCircle( display.contentCenterX, 40, 20) Ball:setFillColor( 0.25, 0.5, 0.25 ) physics.addBody(Ball, 'dynamic', { friction = 0.5, bounce = 0.2, radius = 20 } ) visual:insert( Ball ) sceneGroup:insert( visual )
In Corona for PonyTiled
local physics = require( 'physics' ) local tiled = require( "com.ponywolf.ponytiled" ) local sceneGroup = self.view physics.start() physics.setDrawMode("hybrid") local mapData = require "testmap" local map = tiled.new(mapData) Ball = display.newCircle( display.contentCenterX, 40, 20) Ball:setFillColor( 0.25, 0.5, 0.25 ) physics.addBody(Ball, 'dynamic', { friction = 0.5, bounce = 0.2, radius = 20 } )
Doing this I manage to get the map displayed for both Berry and PonyTiled but none of them apply physics to the tiles with the custom properties.
Another issue is that it displays these weird red lines as you can see in the attached screenshot.
Any help is greatly appreciated.