Draw on entity in platformer example

30 views
Skip to first unread message

Dan Hunter

unread,
Jul 21, 2016, 8:18:23 PM7/21/16
to melonJS - A lightweight HTML5 game engine
Would there be any reason why adding text above an entity would cause it to disappear?

I modified the platformer example game.PlayerEntity and added this into the init:
this.tag = new me.Font("Arial", 14, "white");

then added a draw function just like this:
draw: function(renderer){
    this.tag.draw(renderer, "test", this.pos.x-5, this.pos.y-25);
},

and I get this result:





















the image seems to come back after I remove the draw function, any ideas?

aaron.g...@gmail.com

unread,
Jul 21, 2016, 8:22:11 PM7/21/16
to melonJS - A lightweight HTML5 game engine
Creating your own draw function on top of me.Entity or any other renderable is fine, you just need to make sure you call the parent as well:

draw: function(renderer) {
this._super(me.Entity, 'draw', [renderer]);
// your code here
}

On Thursday, July 21, 2016 at 8:18:23 PM UTC-4, Dan Hunter wrote:
> Would there be any reason why adding text above an entity would cause it to disappear?
>
>
> I modified the platformer example game.PlayerEntity and added this into the init:this.tag = new me.Font("Arial", 14, "white");
>
>
> then added a draw function just like this:
>
> draw: function(renderer){
>     this.tag.draw(renderer, "test", this.pos.x-5, this.pos.y-25);
> },
>
>
> and I get this result:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Dan Hunter

unread,
Jul 21, 2016, 8:29:31 PM7/21/16
to melonJS - A lightweight HTML5 game engine
Wow thanks for the quick response! This was the issue.

Sorry for the newbie question, just starting to play with melonJS and am really liking it.


On Thursday, July 21, 2016 at 8:18:23 PM UTC-4, Dan Hunter wrote:

aaron.g...@gmail.com

unread,
Jul 21, 2016, 8:47:30 PM7/21/16
to melonJS - A lightweight HTML5 game engine
You're welcome! Glad you're enjoying it so far. Please feel free to ask any further questions.

On Thursday, July 21, 2016 at 8:29:31 PM UTC-4, Dan Hunter wrote:
> Wow thanks for the quick response! This was the issue.
>
>
> Sorry for the newbie question, just starting to play with melonJS and am really liking it.
>
> On Thursday, July 21, 2016 at 8:18:23 PM UTC-4, Dan Hunter wrote:
> Would there be any reason why adding text above an entity would cause it to disappear?
>
>
> I modified the platformer example game.PlayerEntity and added this into the init:this.tag = new me.Font("Arial", 14, "white");
>
>
> then added a draw function just like this:
>
> draw: function(renderer){
>     this.tag.draw(renderer, "test", this.pos.x-5, this.pos.y-25);
> },
>
>
> and I get this result:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Reply all
Reply to author
Forward
0 new messages