soulVampire Posted May 11, 2020 Share Posted May 11, 2020 (edited) I have a healthBar entity given by the code below which is in a separate file called health_bar_entity.js(melonjs code base) game.HealthBar = me.Renderable.extend( { init: function(hitPoints, maxHitPoints) { this._super(me.Renderable, "init", [0, -24, 48, 6]); this.z = 100; this.hitPoints = hitPoints; this.maxHitPoints = maxHitPoints; this.health = 1; this.currentHealth = 1; this.setHealth(hitPoints); this.borderColor = '#000'; this.alwaysUpdate = false; }, draw : function(renderer) { if(this.health>=0) { renderer.setColor(this.borderColor); renderer.fillRect(this.pos.x, this.pos.y, this.width, this.height); renderer.setColor('#F00'); renderer.fillRect(this.pos.x+1, this.pos.y+1, this.width-2, this.height-2); renderer.setColor('#0F0'); if(this.health>1) renderer.fillRect(this.pos.x+1, this.pos.y+1, this.width-2, this.height-2); else renderer.fillRect(this.pos.x+1, this.pos.y+1, (this.width-2)*this.health, this.height-2); } }, update : function() { if(this.updateOnce) { this.updateOnce = false; return true; } if(this.health==this.currentHealth) return false; this.health = this.currentHealth; return true; }, setHealth: function(hitPoints) { this.currentHealth = hitPoints/this.maxHitPoints; }, setCurrentAnimation: function() { //do nothing }, setAnimationFrame: function(blarg) { //do nothing } }); and I want to add this to the player entity, but when I try to add to the player by using the code below, this is in the file game_player_entity.js(melonjs code base) this.player_health = 50; this.player_max_health = 100; this.healthBar = me.pool.pull("playerHealthbar", this.player_health, this.player_max_health); console.log('health bar' + this.healthBar); this.addChild(this.healthbar, 9); it give me an error don't know whats going wrong have looked at the api and it seems that it should work Edited May 13, 2020 by soulVampire Refresh description Quote Link to comment Share on other sites More sharing options...
Olloverr Posted December 21, 2022 Share Posted December 21, 2022 Of course, everyone has different problems and diagnoses. With my diagnosis of obsessive-compulsive disorder, I used online therapy for ocd. It greatly improved my condition, helped me to understand what caused it and how I can avoid it later in life. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.