Jump to content

How to draw on particular [TMX] layer?


can2nac
 Share

Recommended Posts

Hi,

in Isometric RPG example (https://github.com/melonjs/melonJS/tree/master/examples/isometric_rpg)

is there a way to draw tile selector on particular layer?

For example, i may add some tilesSelector layer to the TMX map.

In the Isometric RPG example the tile selector is drawn on the top of all layers. I would like to draw it on the basement, under player feet.

 

thanks

Link to comment
Share on other sites

it could as simple as setting the correct z order to your "tile selector object" 

and to make it fully dynamic, you can get the required tile z value using the following code (after your map has been loaded) :

// get the TMX Map Layer called "basement"
var layer = me.game.world.getChildByName("basement")[0];

// get the layer z value
var zOrder = layer.pos.z;

then you can just reuse zOrder when instantiating your tile selector, and it should do the trick :)

Link to comment
Share on other sites

  • 4 months later...

@obiot

sorry, missed you last message.

I'm working on RPG engine which will finally evolve in a post-nuclear style game (i hope). I basically copy Fallout 2 / Tactics engine. So right now player can find his path both realtime and turn based. Also added NPCs. They can only walk and talk with NPC so far. Player also has inventory, profile with stats, quests, inventory, loot. NPCs can walk, talk, take decision if path is blocked. Last thing i did was inventory. Spent quite a lot of time because there are two handed and single handed weapon and items, weapon can have different ammo (9mm bullets can be AP, JHP and some other type, forgot the name), the weapon should be loaded and unloaded properly if it already has bullets of other type. Those details take time. This is a hobby project so i spend like hour or two every day, but i keep moving )) now i'll work on a combat: already finished damage calculation (based on player stats, foe armour, weapon, distance etc - as in F2), will do combat itself next without animation so far. 

One thing on which i spent a lot of time and which still has place for improvements is dynamic z ordering - when player is between two objects and some foe walks around, game should properly reorder objects. So far i put map objects on different layers and placed some empty layers in between. But i do not like the result much.

Link to comment
Share on other sites

wow, that sounds awesome already , any screenshot to share ?

 

else for dynamic z order, it should not be that difficult, container already automatically sort any elements, and as a reminder it is possible to change the sort property for a container , as me.game.world is a me.Container object, so you can do something like the following :

me.game.world.sortOn("z");

see http://melonjs.github.io/melonJS/docs/me.Container.html#sortOn

 

@Parasyte might have further feedback / recommandation on this, as he also played with that while working on neverwell moor.

 

Link to comment
Share on other sites

@obiot

here is a short video https://www.useloom.com/share/046ff4f9cfdd415db6abde13cf8626cf

Back to z ordering. Here is a video of game in debug mode https://www.useloom.com/share/11e48f8ba0c1476ca5f14748ee1b0cd4

As you can see every square with proper markup (NPC, object) influences on a z index of any object above it (red squares above player, chair etc). All NPCs have the same are of influence, they are not shown for the sake of performance.

So we have a matrix of z indexes which stores z index for every tile. Whenever character approaches tile game recalculates those z indexes with regard to those highlighted areas. Originally both NPC are on the same level of tiled map. But they may stand in tiles 3.3, 2.2 and we may also have static object in tiles 4.4 and 1.1. Game recalculates z indexes and tells every participant what their new z index is. When they leave areas of influence their z index gets back to normal.

The thing i don't like is that level designer must not take all that stuff into consideration which he will not most probably )) so i want to rebuild this a little bit and put those static objects in a separate objects (just like NPCs). What i don't know is how to deal with objects which occupy more then 1 tile in such case and will adding such amount of objects influence performance?

I have searched through the network and found only several discussions on the matter with out some proper solution (( But as i wrote before this is a hobby project and i am okay to give it a try )) 

 

Oh, forgot to mention - walls are also marked, because when character is behind them he should not be visible and he should be visible when he is in front of them. Also gaps between rooms were tricky.

Link to comment
Share on other sites

Niiiiiice, it really looks good  !

If I may, would you consider updating to the coming 6.0 version (it's stable, i'm not touching it anymore, and it will be released super soon now) reason I'm saying that is that we added a new damping features for the camera and that will definitely help smoothing the camera movement. Other things is the tons of fix and improvements that should help make the game run smoother generally speaking (https://github.com/melonjs/melonJS/blob/master/CHANGELOG)

 

latest build (2282) :

https://melonjs-builds.s3.amazonaws.com/index.html?prefix=artifacts/master/

latest debugPanel :

https://raw.githubusercontent.com/melonjs/melonJS/master/plugins/debug/debugPanel.js

Upgrade guide (should not take long to update, as it's only about a few previous language extension that we moved under our own namespace) :

https://github.com/melonjs/melonJS/wiki/Upgrade-Guide

 

 

Link to comment
Share on other sites

@obiot

tried v6 today, but game crashed during collision detection. I have attached two screens with crash details. Could you please advice on the solution?

 

Here is the function where it starts

 

  // simulate character's move to specific tile and check for collision
  isCollidingWith: function(col, row) {
    var tileCoords;
    var orgPlayerPosX;
    var orgPlayerPosY;
    var result;

    // save original character's position to be restored when check is done
    orgPlayerPosX = this.pos.x;
    orgPlayerPosY = this.pos.y;

    tileCoords = this.game.refLayer.getRenderer().tileToPixelCoords(col, row);

    this.isRenderable = false;
    this.pos.x = tileCoords.x;
    this.pos.y = tileCoords.y;

    // handle collisions against other shapes
    result = me.collision.check(this);     // this is a function which was called before crash

    this.isRenderable = true;
    // restore original character's position
    this.pos.x = orgPlayerPosX;
    this.pos.y = orgPlayerPosY;

    return result;
  },

 

 

This is a part of my player.js and i use it to build a matrix of tiles where player can't pass. The matrix is used to A-start lib to build patches. 

Screenshot from 2018-07-31 21-33-57.png

Screenshot from 2018-07-31 21-32-38.png

Link to comment
Share on other sites

Oups... this might be my fault, as I changed how collision shapes are « built » internally to prevent unecessary memory allocation.

From what I see somehow a list of « points » are passed to the Polygon constructor (as opposed to a list of me.Vector2d) which then breaks the collision check as the former does not indeed implement the dotProduct methods.

Anyway, it seems that i broke the ability to create shapes using the json data format anyway (either coming from Tiled, or through any serialized data), so i’ll have to fix it later today.

Sorry about that! In the mean time, you can ensure that only a list of me.Vector2d is used, rather than a {x,y} object (or just wait for the fix)

Link to comment
Share on other sites

thanks. I have managed to make it work yesterday by modifying melon.js.

The one thing which i didn't get is 

https://github.com/melonjs/melonJS/wiki/Upgrade-Guide

  • me.Body.accel and me.Body.setVelocity are now deprecated and to be replaced by me.Body.force

But both are still available (see console log on screen attached). Is this correct and there is no need to change them to me.Body.force?

Screenshot from 2018-08-01 19-49-13.png

Link to comment
Share on other sites

Awesome thanks ! And yes they are still available, i’m just trying to progressively « upgrade » the physic implementation, but keeping all the old stuff for now.

Else did you notice any performance improvements, or is it globally stil the same ? 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...