Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by matthewjames

Hello all, I am having issues figuring this one out. I am trying to center the players name over their player entity in MMO-like fashion. Here is what I have so far:

this.font.draw($("#playerOnePage").text(), this.player.pos.x, this.player.pos.y-300, ig.Font.ALIGN.CENTER);

I am using the camera plugin which I think is what is throwing it off. The text is where it should be until the entity hits the outer bounds of the cameras trap and the level starts to scroll and as the entity progress forward, the text outruns the player.

Any ideas?

1 decade ago by Joncom

First of all, the following is a more accurate "centering" over the entity:
var draw_x = this.player.pos.x + this.player.size.x/2;
var draw_y = this.player.pos.y + this.player.size.y/2 - 300;

You can make the font draw over the player regardless of what the camera is doing:
var draw_x = this.player.pos.x + this.player.size.x/2 - ig.game._rscreen.x;
var draw_y = this.player.pos.y + this.player.size.y/2 - ig.game._rscreen.y - 300;

Then draw your font:
this.font.draw($("#playerOnePage").text(), draw_x, draw_y, ig.Font.ALIGN.CENTER);

1 decade ago by matthewjames

@Joncom thanks for the reply, I will try that when I get back. Where does _rscreen come from?

I am working on a Maplestory-esque sidescrolling mmo and so far the only thing that has thrown me for a loop was this :P.

1 decade ago by matthewjames

Thank you very much @Joncom, that worked perfectly.

1 decade ago by Joncom

No problem!

_rscreen is just a "rounded" .screen.

Comment from the ImpactJS source:
Entities reference game._rscreen instead of game.screen when drawing themselfs in order to be "synchronized" to the rounded(?) screen position

1 decade ago by matthewjames

Thanks again @Joncom, helped a lot.
Page 1 of 1
« first « previous next › last »