Tiled Map Engine

@Everyone:

Dusk was released in beta to all the volunteers… Just saying this to keep people posted (and because I see some testers don’t appear to have been notified of the PM I started).

@guillopuyol:

  1. Ceramic (and Dusk) loads table properties through JSON; to enable a property to be read as JSON, prefix it with “!json!”. Then, the remaining area of the property must be in JSON notation.

  2. Yes… Box2D has trouble with side-by-side objects, and any other objects catch at the “seams”. To remove this (or at least minimize the effect), reset the player’s velocity each frame (according to if he’s moving left or right).

  3. Currently, you’ll have to disable tile culling to keep the missing tiles from showing up. As for the seams between tiles, this is a very common problem that can be fixed usually with this:

[lua]

display.setDefault(“minTextureFilter”, “nearest”)

display.setDefault(“magTextureFilter”, “nearest”)

[/lua]

Where is the dusk beta Caleb?

If you want to be a part of the beta testers, send me a PM and I’ll get you a copy when I get everything together.

  • From earlier

A number of people PM’d me, and I gave them access to it for testing.

If you’d like to join the testers, I’ll send you a copy - just say :).

  • Caleb

I’m not dead! :slight_smile:

Beta 0.1 version is getting closer to the release date!

If you want to be a part of the beta testers, send me a PM and I’ll get you a copy when I get everything together.

  • Caleb

+10 for this.

Well I’m testing it and I have firts trouble, my game is a top down car game and I need a UI with some buttons in top. I had implemented a joystick and 2 buttons, my problem is when map is loaded I canot see them.

How to manage my ui in front of map layers and always visible?

Thank u so much

It’s probably best to create a group system with several layers and insert the map into the bottom layer. Your UI can go in the top layer, for it to be visible above the map.

Very simple example:

[lua]

local gui = display.newGroup()

gui.back = display.newGroup()

gui.front = display.newGroup()

gui:insert(gui.back)

gui:insert(gui.front)

gui.back:insert(map)

gui.front:insert(ui)

[/lua]

  • Caleb

Works ok now but camera is not runing,

I have a trouble now, when i turn a title in tileeditor with ‘x’ or ‘z’ keys ceramic can not find that tile. T_T

As I could see in code, ceramic is not contemplating rotating tiles because gid is number of tile in tileset, but in tiled gid save the state of tile, as seen here:

https://github.com/bjorn/tiled/issues/19

code: https://github.com/bjorn/tiled/blob/cf9b4b055f9dd4d38a9ff29f7f50662e29541a24/src/libtiled/mapwriter.cpp#L390

// Bits on the far end of the 32-bit global tile ID are used for tile flags

const int FlippedHorizontallyFlag = 0x80000000;

const int FlippedVerticallyFlag = 0x40000000;

if (cell.flippedHorizontally)

        gid |= FlippedHorizontallyFlag;

    if (cell.flippedVertically)

        gid |= FlippedVerticallyFlag;

so if tile is fliped horizontally gid of tile is 0x80000000 + id of tile

y have done an example to see it, x1 and y1 has normal tile but x2 y2 has fliped tile

“data”:[121, 2147483769, 141, 2147483789],

0x80000000 is  2147483648   in base 10 format so 2147483769 =  2147483648  + tile 121

Unknown to most, TILED does support rotating/flipping tiles, although using it in rendering takes a bit of code change on our side.
When a tile is rotated in TILED, it’s tile-index value in JSON changes, effectively, it appears that the app will set the high-4 bits to a specific value representing the state of the tile. So if you make the top 4 bits of a 32 bit integer, you’ll see:

  • Normal = 0,
  • Rot 90 = 0xA0000000,
  • Rot 180 = 0xC0000000,
  • Rot 270 = 0x60000000,
  • Flip Y = 0x40000000,
  • Flip X = 0x80000000,
  • Flip Y & Rot90 = 0x20000000,
  • Flip X & Rot90 = 0xE0000000,

 

relater article here http://mainroach.blogspot.com.es/2013/02/fast-html5-canvas-rendering-tiled-maps.html

I added this code

–constans for Rotate and flip tiles

local rot90 = 10485760 --0xA0000000,

local rot180 = 3221225472 --0xC0000000,

local rot270 = 1610612736 --0x60000000,

local flipY = 1073741824 --0x40000000,

local flipX = 2147483648 --0x80000000,

local flipY_Rot90 = 536870912 --0x20000000,

local flipX_Rot90= 3758096384 --0xE0000000,

–On layer.draw function after geting id from tilest I insert this code to identificate the rotation and to get real id 

–variable fliped will have the real orientation and flip of tile

local id=mapData.layers[i].data[(y-1)*data.mapWidth+x]

                                                                                smm >>>> Check if tile is flip or rotated 

                                                                        local fliped = false

–                                                                        Tile is fliped must get real id

                                                                        if id >= flipY_Rot90 then

                                                                            if id >= flipY then

                                                                                if id >= rot270  then

                                                                                     if id >= flipX  then

                                                                                        if id >= rot90  then

                                                                                            if id >= rot180  then

                                                                                                if id >= flipX_Rot90  then

                                                                                                    fliped = flipX_Rot90

                                                                                                else

                                                                                                    fliped = rot180

                                                                                                end

                                                                                            else

                                                                                                fliped = rot90 

                                                                                            end

                                                                                        else

                                                                                            fliped = flipX 

                                                                                        end

                                                                                    else

                                                                                        fliped = rot270 

                                                                                    end

                                                                                else

                                                                                    fliped = flipY 

                                                                                end

                                                                            else

                                                                                fliped = flipY_Rot90

                                                                            end

                                                                            id = id - fliped 

                                                                        end

–                                                                      smm <<<<

–finally when tile is created does rotation or flip

smm >>>> rotate tile if fliped

                                                                                    if fliped  then

                                                                                        if fliped == rot90  then

                                                                                            tile.rotation = 90

                                                                                        elseif fliped == rot180 then

                                                                                            tile.rotation = 180

                                                                                        elseif fliped == rot270 then

                                                                                                tile.rotation = 270

                                                                                        elseif fliped == flipY then

                                                                                                tile.yScale  = -1 

                                                                                        elseif fliped == flipX then

                                                                                                tile.xScale  = -1 

                                                                                        elseif fliped == flipY_Rot90 then

                                                                                                tile.yScale  = -1

                                                                                                tile.rotation = 90

                                                                                         elseif fliped == flipX_Rot90 then

                                                                                                tile.xScale  = -1

                                                                                                tile.rotation = 90

                                                                                        end            

                                                                                    end

–                                                                                    smm <<<< end if tile is flipped

(Sorry for lurking…)

I looked at flipped/rotated tiles a while back and there’s a simpler way to get at the bitwise stuff…

[lua]

function hasbit(x, p)

  return x % (p + p) >= p       

end

function setbit(x, p)

  return hasbit(x, p) and x or x + p

end

function clearbit(x, p)

  return hasbit(x, p) and x - p or x

end

[/lua]

You can test pretty easily…

[lua]

local flipX = toNumber(“80000000”,16)

local flipY = toNumber(“40000000”,16)

if hasbit(id,flipX) then tile.xScale  = -1 end

if hasbit(id,flipY) then tile.yScale  = -1 end

[/lua]

…and clear that bit…

[lua]

id = clearbit(id,flipX)

id = clearbit(id,flipY)

[/lua]

Quick question for anyone who is knowledgeable with manipulating tiles / grids.

Im building a 3D engine which takes a tiled map and then draws it in 3D, with a camera, screen etc… Comparable to mode 7 I suppose.

To keep the processing down to a minimum I’m doing a field of view on the grid, simple Octant stuff depending on camera angle.

Its working ok but its still providing many more tiles than are visible with the camera, meaning I’m wasting cycles calculating stuff that won’t be seen.

What I really need is a way of getting all the tiles between at a given angle / fov. No point using any real fov scripts as that usually calculate walls / blocked tiles and are too slow. Need something fast.

I just ran into Ceramic and Tiled. This is a great tool! I’m following the, excellent, video tutorial and ran into a problem.

When I create an object on an object layer, Ceramic should create a vector shape. But this doesn’t happen for me. I don’t see anything. Though if I create an image on the object layer it will show. Though, if I activate physics, I’ll see the outline of the object in hybrid draw mode. 

I notice that the objects created for physics are offset to the upper let by half their width and height. I’m guessing that this is related to changes in the latest version of Corona and the Graphics 2.0 changes. 

The name is changing yet again…

Many apologies; the thought occurred to me that people might think I’m naming this engine for or with any connection with the “Twilight” movies (whatever they are - never seen them, nor do I plan on seeing them). So the new name is the Dusk Engine, or Dusk for short :slight_smile:

  • Caleb

@Matthew Pringle:

I, quite honestly, can help you not. I’ve never done anything in 3D (or even pseudo-3D). You might look into this (don’t know, didn’t look into the code); it runs pretty fast.

@soggybag:

[lua]

ceramic.virtualObjectsVisible = true

[/lua]

Should help you with the invisible things.

As for the offsets, that is a problem with Ceramic and G2.0 and will be fixed with Dusk.

Hello,

I’m creating a project using Ceramic (is that the name?)  and I’m having trouble finding a way to create an animated sprite character.

My player (the one that is followed by the camera) was created as an image object layer in Tiled… how should I create my player (and enemies) so that I can assign sprite sheets to them and animate them properly?

Sorry about the name chaos :slight_smile:

Here’s a clarified explanation of the name: This engine was conceptualized, and the concept version was named CoronaTiled. Development continued, and thus was born Ceramic, the name given to the early (experimental) builds of this engine (while we were getting its bearings on what it would be). A new version is coming out in a bit (it’s been in the workings for quite some time) that will be named Dusk, and it’ll be the “real” product.

Anyway, to get on with the question.

At the moment, there is no [insert engine name :)] approach for creating complex objects from Tiled. For the present time, you’ll have to create objects as you normally do.

You can create any objects that aren’t buildable from Tiled simply by creating them normally, and then adding them to the map. To add them to the map, simply access a layer of the map and :insert it into the layer. Like so:

[lua]

map.layer[1]:insert(myObject)

[/lua]

Simple :slight_smile:

  • Caleb

@guillopuyol

as caleb said, you need to do this from corona

you need to have the sprite sheets and load them to corona, like this:

------------------------------------------------------------------------------ -- Create Enemies ------------------------------------------------------------------------------ -- image sheet local sheetData1 = { width=30, height=21, numFrames=14, sheetContentWidth=420, sheetContentHeight=169 } local enemySheet = graphics.newImageSheet( "tilesets/xander\_goomba\_sheet.png", sheetData1 ) local sequenceData = { { name="seq1", sheet=enemySheet, start=1, count=12, time=600, loopCount=0}, { name="seq2", sheet=enemySheet, frames={ 13 }, time=50, loopCount=1} } local enemy = display.newSprite( enemySheet, sequenceData ) enemy:setSequence("seq1")

in my example i have 2 sequences from the same sprite sheet, i start with seq1 wich is the enemy walking, then when you kill the enemy, change it to seq2 (enemy dying)

you can do the same for the player and change sequences for standing, jumping, running, etc… but this works if the images in the sheet are the same width and height… if they change the width and height you need complex options in the image sheets, here is the documentation:

http://docs.coronalabs.com/guide/media/imageSheets/index.html

hope that helps and good luck :slight_smile:

Dont worry by the name caleb ;)  , in fact I would name it calebTile engine, but dusk engine sound very well.

I have found troubles with cunning tiles, running the game in the device, the fist time map is load there are some blck holes in some tiles and apears other tiles that are not in these coordinates,

another trouble is that when runing on fast speed I could see black holes in borders, i supose are tiles that are not displayed yet.

I think the second could be solved by adding a customizable offset in layer rendering so it will render x tiles more for each side of display. I tried to find it but I lost in code, sorry  :unsure: 

That should all get fixed once regular development on Dusk starts.

At the moment, it’s in the makings, though in a bit, I’ll release it the pre-beta version for testers.

  • Caleb