axaq / traviso.js

Traviso is an open source JS engine that makes it easy to build isometric applications that run in a web browser.
MIT License
309 stars 42 forks source link

Feature request: Add text on top of objects #9

Closed Clint65 closed 6 years ago

Clint65 commented 6 years ago

Hello, I've discovered Traviso, and I'm very interested to play with it. I'm trying to display text over tiles or objects. I manage to do something like this: function onEngineInstanceReady () { var basicText = new PIXI.Text('Basic text in pixi'); pixiRoot.stage.addChild(engine); var pos ={}; pos.r=11; pos.c=12; engine.addCustomObjectToLocation(basicText,pos); }

The issue is that text is displayed below objects. Is there any way to keep it on top of everything ?

Thanks in advance !

Clint

victorsbd commented 6 years ago

Hello Clint65,

After add a new object, you can call the function arrangeDepthsFromLocation manually with this argument { c: this.mapSizeC-1, r: 0 }. It should draw your new object in front of the others objects.

Regards

Clint65 commented 6 years ago

Thanks ! But it still not working if my text is at the same location of another object. The mapData.json file seems to be loaded after addCustomObjectToLocation, and the arrangeDepthsFromLocation doesn't seem to deal with multiple objects at the same location. I'll try to add a callback "dataloadedcallback"

Clint

victorsbd commented 6 years ago

If you are on the method onEngineInstanceReady the mapData.json should be already loaded. I did some changes to handle more than one object at the same location so for that reason maybe i have another behavior when i arrange the depths of the objects.

Clint65 commented 6 years ago

Okay, I understand.

I found another way to do this: basicText.x = engine.getTilePosXFor(10,5); basicText.y = engine.getTilePosYFor(10,5); var mycont = new PIXI.Container(); engine.mapContainer.addChild(mycont); mycont.addChild(basicText);

I'm executing this code in onEngineInstanceReady, this way myContainer is always drawn in top of others.

Many thanks !

Clint