Tiled Map Engine

Question for everyone:

I’m currently working on the camera system, so kindly tell which of these you’d prefer:

  1. All the camera methods (get/set view position, update camera, etc.) to be inside the root map object:

[lua]

map.setViewpoint()

map.setDamping()

map.getViewpoint()

map.updateCamera()

[/lua]

  1. All the camera methods to be inside their own object (likely “view” or “camera”), a child of the map:

[lua]

map.view.setViewpoint()

map.view.setDamping()

map.view.getViewpoint()

map.view.updateCamera()

[/lua]

If you chose option 2, please say what you’d like the object to be named (“view”, “camera”, or something else).

Thanks!

  • Caleb

Forgot to mention that I’m defaulting to option #1 :slight_smile:

  • C

i vote for option 1 too!

keep it up!! :slight_smile:

Another quick question:

Would you rather the first release be without culling (thereby speeding up the release date a bit) or wait for the full thing, with culling included?

-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]

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

Been out of town the last few days - sorry for not updating the progress page.

I’ve got scaled maps (layer scaling and map scaling at the same time, if you want) working, but have yet to do tracking bounds (with scaling).

The engine grows ever closer to release date! (for everyone who’s wondering, it’s probably about 75-80% done)

  • C

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

Caleb,

Thanks for your answer.  I’m having some problems with my map:

  1. When I enter the property shape in one of my tiles, it is still being drawn as an square physics object.  Here are the points I have entered:

{-16,-16,-12,-16,16,16,0,16,-16,0} 

I tried entering with and without the brackets with no luck…

  1. As my animated player character is running over the ‘floor’ tiles, sometimes it seems as if he is getting stuck… feels like he hits the top edge of the tile and a collision happens.  If I make him jump and move forward a bit, it runs over that tile and hits the next.  Any ideas what could be causing this behavior?

  2. I tested the map on a Kindle Fire and sometimes there is a tile missing, and in some cases I see lines between the tiles that “give away” the tile structure… Is there a work-around for this?

THANKS in advance for all your help!