-
Currently struggling with getting an absolute-positioned hud onscreen in a project using the tiled plugin. No matter what I try, the hud moves with the background as it scrolls around. The clearest way seems to be using ScreenElement as described here: I can get something sort of working by passing the camera into the screenElement and positioning contents relative to that, but it still shifts around slightly and just seems hacky. Is there a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @depsypher great question! There are a couple strategies here:
const HUDEntities = game.currentScene.world.entityManager.getByName("HUD");
for (let entity of HUDEntities) {
const tx = entity.get(ex.TransformComponent);
if (tx) {
tx.coordPlane = ex.CoordPlane.Screen;
}
}
// Add tiled map objects to the scene
map.addTiledMapToScene(game.currentScene);
// Manage UI
const screenElement = new ex.ScreenElement({
pos: ex.vec(10, 10),
width: 600,
height: 20,
color: ex.Color.Green,
z: 100
});
game.currentScene.add(screenElement);
|
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks for the nudge in the right direction! I got what I was looking for using a mix of 1) and 2) above. The piece I was missing was setting coordPlane on the screen element contents:
I'm trying to detect which tile from the tileset the player is on... working through it, will start a new discussion if I get really stuck. Thanks for all the help so far. |
Beta Was this translation helpful? Give feedback.
Hi @depsypher great question! There are a couple strategies here:
TransformComponent
to screen coordinates. (You'll need to manage scale manually since switching to the screen coordinates takes the camera transform out of account). This might be wonky to work with since the position in Tiled will no longer match up to the screen in the game.