Reading objects prefs at specific map position in MTE

Hello

Working on my scroll-shooter I came across following requirement I need to implement for the level engine. I cant move on as I stucked with implementation problem.

What I do is scroll level using mte.moveCameraTo to scroll to the end of level (horizontaly).

I want to spawn enemies or bosses at specific point and time of the level map. So I ceated a layer in tiled where I put objects to indicate the place on the map where for example enemies have to be spawn, or the boss should appear on the screan.

the problem I have is that this method dont work for me or I cant handle it.

my question:

How do I check if an specifi object is on screen (camer moved to its place) adn how do I read it’s parameters/propoerties?

I’m confused after checking MTE example projects and cant make the thing to work.

Any hints are appreciated.

[edit]

my first quess was to use mte.addObjectDrawListener(name, listener)

but it is not working for me

Hello FatPixel,

The function mte.addObjectDrawListener(name, listener) is probably not going to help you in this situation.

I suggest you try the following:

You can create a tile layer and use tiles of your choice to mark where enemies should spawn. Give each marker tile a property such as “enemySpawner” and set the property to anything you like. In MTE call mte.addPropertyListener(“enemySpawner”, myListener), naming myListener whatever you’d like. Whenever one of your tiles which has the “enemySpawner” property enters the active culling region- an area slightly larger than the screen- MTE will throw an event triggering your myListener function. The event parameter of myListener will contain the information you need; event.target is the tile, event.target.locX is the X location of the tile on the map, and event.target.properties is the table of properties you gave the tile in Tiled. 

You can see a usage example of property listeners in scene.lua of the IsometricStoryboardTMX sample project. The listeners start at line 133, the addPropertyListener() functions are called on lines 176 and 177.

You can keep the marker tiles from appearing on the screen by giving the layer a “noDraw” property and setting it to true. 

OK

will try that later.

what i do now as a replacement solution is to check camera position and objects x position

when they match (math.floor(obj.x)) i spawn sprites… kinda works but your solution is much “cleaner”. 

gonna try that.

thanks for hits!

all the best for 2014!

OK

The thing you sugested seams to work well.

But cant we do the same “properties listener” method with objects rather than tiles?

BTW: I wonder how adding layers affects the performance.

I noticed some slow downs after moving my test code to real iPad (ipad 2 actually so its slow one)

but till now I wasnt aware that it works slow on real iPad rather than Corona simulator.

Should we  start maybe a new thread about performance considerations?

The “property listener” method doesn’t work on Tiled objects at the moment because those objects are not handled the same way as tiles. MTE draws tiles when they come on screen. Objects are data stored in the map table. 

Another method you might try, if you prefer working with objects, is to get the X and Y locations of the edges of the active map region and to check each location for an object. You can get the locations of the screen edges with mte.getScreenExtent(). Without any arguments, this function will return a table with top, left, bottom, and right parameters. Top is the Y location of the top edge of the active region, right is the X location of the right side of the screen, and so on. You could use  for-next loop to iterate through all the locations on one edge of the active region, checking each location for Tiled objects.

The Corona Simulator is not a virtual machine, that is to say it does not simulate the performance of the devices you select for display. The Corona Simulator will always run using the full power of your PC, whether you select iPhone 4 or iPad Retina. The only way to get a true measure of how the code will run on the device is to run the code on the actual device. I recommend testing on real hardware regularly for this reason! You don’t want to get caught with slow code too far into a project.

you can find map x and y of obj using obj.locX and obj.locY.

Hello FatPixel,

The function mte.addObjectDrawListener(name, listener) is probably not going to help you in this situation.

I suggest you try the following:

You can create a tile layer and use tiles of your choice to mark where enemies should spawn. Give each marker tile a property such as “enemySpawner” and set the property to anything you like. In MTE call mte.addPropertyListener(“enemySpawner”, myListener), naming myListener whatever you’d like. Whenever one of your tiles which has the “enemySpawner” property enters the active culling region- an area slightly larger than the screen- MTE will throw an event triggering your myListener function. The event parameter of myListener will contain the information you need; event.target is the tile, event.target.locX is the X location of the tile on the map, and event.target.properties is the table of properties you gave the tile in Tiled. 

You can see a usage example of property listeners in scene.lua of the IsometricStoryboardTMX sample project. The listeners start at line 133, the addPropertyListener() functions are called on lines 176 and 177.

You can keep the marker tiles from appearing on the screen by giving the layer a “noDraw” property and setting it to true. 

OK

will try that later.

what i do now as a replacement solution is to check camera position and objects x position

when they match (math.floor(obj.x)) i spawn sprites… kinda works but your solution is much “cleaner”. 

gonna try that.

thanks for hits!

all the best for 2014!

OK

The thing you sugested seams to work well.

But cant we do the same “properties listener” method with objects rather than tiles?

BTW: I wonder how adding layers affects the performance.

I noticed some slow downs after moving my test code to real iPad (ipad 2 actually so its slow one)

but till now I wasnt aware that it works slow on real iPad rather than Corona simulator.

Should we  start maybe a new thread about performance considerations?

The “property listener” method doesn’t work on Tiled objects at the moment because those objects are not handled the same way as tiles. MTE draws tiles when they come on screen. Objects are data stored in the map table. 

Another method you might try, if you prefer working with objects, is to get the X and Y locations of the edges of the active map region and to check each location for an object. You can get the locations of the screen edges with mte.getScreenExtent(). Without any arguments, this function will return a table with top, left, bottom, and right parameters. Top is the Y location of the top edge of the active region, right is the X location of the right side of the screen, and so on. You could use  for-next loop to iterate through all the locations on one edge of the active region, checking each location for Tiled objects.

The Corona Simulator is not a virtual machine, that is to say it does not simulate the performance of the devices you select for display. The Corona Simulator will always run using the full power of your PC, whether you select iPhone 4 or iPad Retina. The only way to get a true measure of how the code will run on the device is to run the code on the actual device. I recommend testing on real hardware regularly for this reason! You don’t want to get caught with slow code too far into a project.

you can find map x and y of obj using obj.locX and obj.locY.