Million Tile Engine Beta Release

Thanks for the performance numbers, AppDeveloperGuy! That is good to know.

I’ll be spending the next few days finalizing and testing MTE’s new functions and features ahead of a new release on Friday of next week. 

New functions include:

getSprites(parameters)

getTilesWithProperty(key, value, level, layer)

preloadMap(src, directory)

getLoadedMaps()

unloadMap(mapPath)

drawObjects()

drawObject(name)

redrawObject(name)

I’ve changed loadMap() and refresh() to support selective map unloading. A developer can now choose to hold maps in memory to facilitate loading into them quickly at a later time. 

The new cullingMargin parameter for goto() will allow the dev to specify how far the active culling region should extend beyond the edges of the screen. The Physics simulation will also continue to run in this enlarged region.

MTE is now better at filling the screen when “letterbox” scaling is set in the config.lua file. 

I’ve made several improvements to MTE’s handling of physics objects. Physics objects may now be moved with MTE’s standard movement functions such as moveSpriteTo(). 

Non-physics sprites will no longer automatically park unless their “park” flag is set to true. 

Finally, of course, there is the addition of physics and draw support for Tiled’s Polygon, Polyline, Ellipse, and Box/Rectangle objects. All of these objects can be rendered to the screen as vector objects and given physics bodies. They will all automatically self-generate matching physics shapes if their “shape” property is set to auto or nil. Developers can now also modify a Tiled Object’s physics/display properties and redraw that object. 

Alright, I ran a few tests and found that MTE works quite well with the ultimate config.lua file, even with it’s variable width and height parameters. Dynamic content scaling works properly as well. The easiest way to match the height of your level to the height of the screen is to represent the height in number of tiles and go from there. For example, if you always want the display area to be ~10 tiles in height;

local blockScale = display.viewableContentHeight / 10 --tiles mte.goto({ locX = 53, locY = 40, blockScale = blockScale})

When you call goto() MTE creates a master group containing groups for each of the layers, each of which contains the tile display objects for your map. It then manages their positions as you send movement commands, performing culling and it’s other functions on them.

Optimum tile sizes become less important when the engine scales them for you, but I personally prefer sticking to the tried and true 32 x 32 or 64 x 64 pixel tiles, sometimes a little larger or smaller, always divisible by 2 (or 4 if possible). Most of the sample projects included with MTE use 32x32 tiles. 

At the moment backgrounds are assembled from tiles. You can scale those tiles up and apply a parallax effect to the layers to produce the desired results, but you are limited to tiles of the same native resolution as the rest of the map. I will add more flexibility to address this through updates, though I don’t have a firm ETA on that.

A technique I use in the platforming sample projects is to take a screen capture of a background layer in Tiled, create a nice clean PNG of the whole layer, and load that as a sprite, however this does not efficiently use texture memory and the possible size is limited to the max texture size of the devices (1024x1024 or 2048x2048).

anyone have a sample project they could post showing now to use MTE with dynamic image selection - I have a support email question to dyson122 but depending on his availability if someone could post I could start looking at…in particular:

  • how many tiler maps/json files are required (just one, or one for each resolution?)

  • what is the code to setup the map (e.g. what json file and PNG file names do you refer to)

  • config.lua extract just to see what you have

  • so ideally the smallest little sample that when you change what device you’re viewing from it starts accessing the higher resolution tile images to create the map

Don’t have anything on-hand but I’ve been using MTE with the ultimate config.lua method for quite some time now. 

Preface:

  1. I’m building a game world with 16x16px tiles. So in Tiled, I’m working with the 16x16 assets. If I was using @2x I would build the world using the original assets, not the @2x.

  2. This is obviously too small for even the 3GS, so I scale up appropriately based on device. 3x (48x48) is great for phones, 4x for Tablets. The ultimate config.lua method (and device.lua) help you pinpoint what devices to feed what scale factor on startup.

  3. The scaling works because I use GL_NEAREST - which gives you pixel-perfect scaling. I’ve used @2x assets before with MTE but GL_NEAREST lets you skip it entirely and use one asset for all resolutions…providing you don’t need any kind of scale-smoothing done.

might be different to what I am after I think. I want to be able to have 3 different resolution versions of each tileset, with different prefixes on the file names per config.lua. Then I need MTE/COrona work together to load the right resolution version.

PS.  So just checked the Corona doco, so what I’m after is how to use MTE for Dynamic Image Selection per http://docs.coronalabs.com/guide/basics/configSettings/index.htmlhttp://docs.coronalabs.com/guide/basics/configSettings/index.html.  

Also, anyone know do you get the top/left of your map to start at the top/left of your screen?  I get black margins at the left and top.  Also I guess then in general, how do you get MTE to make sure you never have any black margins showing inside the content area?  (in my case I want the player to start somewhere typically in the top/left hand side of the map.  As the player moves to the right say, when they get towards the end of the right hand side of the map, the right hand side of the map should remain aligned with the right hand content area, and never go any more to the left exposing some black space)…

Putting the finishing touches on two last-minute additions for Friday’s update:

  1. In Tiled it is possible to load a tileset with larger tiles than the tile size of the map. These large tiles now display correctly in MTE.

  2. Listeners. The function addPropertyListener(property, listener) will dispatch an event whenever a tile with the specified property loads into MTE’s active culling region; essentially, the event fires when a tile generates a display object for itself. The function addObjectDrawListener(name, listener) dispatches an event when MTE draws an object with the matching name. This only happens when the player calls one of the object draw methods, for example drawObjects(). 

plb.png

In the above image every tile with the “orientation” property is tinted red, every tile with the obsolete “m” property is rotated 45 degrees, and the static physics object named “testRect1” is rotated 45 degrees.

local onOrientationProperty = function(event) event.target:setFillColor(255, 0, 0) end mte.addPropertyListener("orientation", onOrientationProperty) local onMProperty = function(event) event.target.rotation = 45 end mte.addPropertyListener("m", onMProperty) local onTestRectObject = function(event) event.target.rotation = 45 end mte.addObjectDrawListener("testRect1", onTestRectObject) mte.goto({locX = locX, locY = locY, blockScale = blockScale, cullingMargin = {top = 400, bottom = 400, right = 400, left = 400}}) mte.drawObjects()

You can also generate sprites from tiles as in the following image:

2y9a.png

Every tile with the “m” property generates a sprite duplicate and then destroys itself.

local myObjects = {} local onMProperty = function(event) myObjects[#myObjects + 1] = event.target:makeSprite() myObjects[#myObjects].bodyType = "dynamic" mte.updateTile({locX = event.target.locX, locY = event.target.locY, tile = 0, layer = event.target.layer }) end mte.addPropertyListener("m", onMProperty)

How would enemies be handled if it doesn’t support corona’s built in physics engine. I bought it today!

Ah, but MTE does support Corona’s built-in physics engine, and it’ll have even better support this Friday! I suggest checking out the CastleDemo, RotateConstrainStoryboard, and non-physics Platformer sample projects to see what non-physics movement and collision detection entails. It does get rather difficult as you try to handle more complicated movement and collision detection, which is one of the reasons I’ve been working to bring Physics support to the engine.

Cool. Im also trying to make the player move using the accelormeter? 

Hi, just a quick question. I’m trying to make a game that has a destructible map. How can I overwrite a block at a specific x,y in the map?

corona5196, you can use updateTile(parameters) to remove a tile by setting it to 0. For example:

mte.updateTile({locX = 10, locY = 10, tile = 0, layer = 1})

SurfieldA, I suggest you try Corona’s Accelerometer sample in /CoronaSDK/SampleCode/Hardware/Accelerometer1/. Using the accelerometer to move a sprite would amount to choosing the force you wish to apply and applying it to the player in the accelerometer runtime event. If the player is a physics object you can use the standard physics object functions for applying force or linear velocity. Otherwise you can use mte.moveSprite(sprite, velX, velY). 

does this support the world rotating

I’ve had MTE running for 24 hours no probs (the earth did a whole rotation in this time)  :)            sorry couldn’t resist

understand i have them urges from time to time

@dyson122 - some things I have noted when testing re enabling physics via Tiler

a) Layer properties doesn’t seem to work - add physics=true & bodyType=static to one of the layers does not cause the tiles in the layer to pickup the properties?   (I can put the same properties against specific tiles and it works, this is kind of important as I can’t work out how to do a bulk update of these properties against a bunch of tiles at the same time)

b) Object Layer - only the tile type objects seem to work - really need the other objects to work as this is invaluable - e.g. setting up landing lines, walking lines across multiple tiles etc - can we have this please?

Hi, I am having real problems with MTE. I have had the engine for a while now and have finally got round to testing it out (not the demos).  I am following along with the tutorial in “MTE Tilesets, Map Structure, Getting Started.pdf”.

My code is as follows…

local mte = require"mte" mte.loadMap("cavemap1") mte.goto({locX = 10, locY = 10, blockScale = 32})

I am receiving the following message when trying to launch my code…

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2013.1137
WARNING: Cannot create path for resource file ‘cavemap1.json’ b/c it does not exist.

Runtime error
d:\cliff\docume~1\outlaw\sandbox\23\mte.lua:5052: attempt to concatenate local ‘path’ (a nil value)
stack traceback:
        [C]: ?
        d:\cliff\docume~1\outlaw\sandbox\23\mte.lua:5052: in function ‘loadMap’
        d:\cliff\docume~1\outlaw\sandbox\23\main.l

Now if I manually copy the cavemap1.json file into that folder it is all fine. That is until the next error message…

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2013.1137
cavemap1.json loaded
World Size X: 128
World Size Y: 128
Levels: 1
Reference Layer: 1
Runtime error
d:\cliff\docume~1\outlaw\sandbox\23\mte.lua:3552: Incorrect number of frames (w,h) = (32,32) with border (1) in texture (w,h) = (512,512). Failed after frame 226 out of 227.
stack traceback:
        [C]: ?
        [C]: in function ‘newImageSheet’

What gives here? Am I missing something?

A little help would be appreciated. I don’t see what I am doing wrong and don’t think it should be this frustrating to get 3 lines of flipping code to run.

BTW, I am very new to corona etc, please help :slight_smile:

@corona5196-

You forgot to load the tileset you used to create the map.  Without and image, it can’t use the .json file.  I’m not sure what your tileset is called… or if it is .png or .jpg, (we’ll call it cave1mapTileSheet.png) but it will look like this:

local mte= require “mte”

mte.loadTileSet(“cave1mapTileSheet”, “cave1mapTileSheet.png”)  --this is your problem, you forgot this–

local map = mte.loadMap(“cave1map”)

mte.goto({ locX = 10, locY = 10, blockScaleX = 32, blockScaleY = 32})

@jstrahan-

What do you mean by world rotating?  …Do you mean device rotating?  If your answer is yes to the second question, then yes, it could support device rotating.  I currently am running my game in portrait mode and dyson’s examples are in landscape mode…  To make it efficient, however, one may have to change the height and width of the displayed screen tiles when rotation the screen (since the dimensions are different…).

Hey thanks for the reply. My code now reads…

local mte = require"mte" mte.loadTileSet("cavetiles1", "cavetiles1.png") mte.loadMap("cavemap1") mte.goto({locX = 10, locY = 10, blockScale = 32})

I am getting the following error…

Copyright © 2009-2013  C o r o n a   L a b s   I n c .
        Version: 2.0.0
        Build: 2013.1137
WARNING: Cannot create path for resource file 'cavemap1.js
ist.

Runtime error
d:\cliff\docume~1\outlaw\sandbox\23\mte.lua:5052: attempt
path’ (a nil value)
stack traceback:
        [C]: ?
        d:\cliff\docume~1\outlaw\sandbox\23\mte.lua:5052:
        d:\cliff\docume~1\outlaw\sandbox\23\main.l

Any suggestions?

@jstrahan; Yes if you don’t plan to use physics, no if you plan to use physics. You can rotate the world by getting the map obj and setting it’s rotation property as you would any group, but physics bodies steadily lose their minds the more the map rotates. I’ll look into that problem. Was there a specific effect you’re aiming for?

@greg; Tile’s take on layer physics properties only when they A) have the physics=true property and B) do not already have the physics properties in question. Changing the layer physics properties will not currently force an update to the tiles in the layer. I will add a means of doing so in the coming update.

I’m actually currently working on adding polygon, polyline, box, and possibly ellipse objects to the physics support! Those will be available in the next update as well.

@corona5196; The most common causes of these problems are misplaced files and misspelled filenames. Your code expects cavemap1.json to be in the root directory of your app. You should also make sure you aren’t missing any capitalization.

I’ve run out of time for now, but I will be on later today to help as well.