{"id":14971127,"url":"https://github.com/samme/phaser-component-health","last_synced_at":"2025-10-26T14:31:05.243Z","repository":{"id":32737654,"uuid":"139344483","full_name":"samme/phaser-component-health","owner":"samme","description":"Health methods and events for Phaser 3","archived":false,"fork":false,"pushed_at":"2023-01-08T19:09:02.000Z","size":1209,"stargazers_count":13,"open_issues_count":2,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-31T20:18:12.410Z","etag":null,"topics":["phaser","phaser-component","phaser3"],"latest_commit_sha":null,"homepage":"https://codepen.io/samme/pen/BeyZpX","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-01T16:26:50.000Z","updated_at":"2024-05-29T11:23:10.000Z","dependencies_parsed_at":"2023-01-14T22:05:06.062Z","dependency_job_id":null,"html_url":"https://github.com/samme/phaser-component-health","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samme%2Fphaser-component-health","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samme%2Fphaser-component-health/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samme%2Fphaser-component-health/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samme%2Fphaser-component-health/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samme","download_url":"https://codeload.github.com/samme/phaser-component-health/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238347578,"owners_count":19456962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["phaser","phaser-component","phaser3"],"created_at":"2024-09-24T13:44:45.163Z","updated_at":"2025-10-26T14:31:05.237Z","avatar_url":"https://github.com/samme.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Phaser 3 Health Component\n=========================\n\nFlexible, data-based health component.\n\nExamples\n--------\n\n```javascript\n// Add component to *one* game object and assign health=1, minHealth=0, maxHealth=2\nPhaserHealth.AddTo(sprite, 1, 0, 2);\n\n// Same, in two calls:\nPhaserHealth.AddTo(sprite).setHealth(1, 0, 2);\n\n// Add component to Sprite class\nPhaserHealth.MixinTo(Phaser.GameObjects.Sprite);\n// Then set health values on a game object\nvar sprite = this.add.sprite(/*…*/).setHealth(1, 0, 2);\n\n// Hide and deactivate sprite when health decreases below 0\nsprite.on('die', function (obj) {\n  obj.setActive(false).setVisible(false);\n});\n\n// Show and activate sprite when health increases above 0\nsprite.on('revive', function (obj) {\n  obj.setActive(true).setVisible(true);\n});\n\n// React to health changes\nsprite.on('healthchange', function (obj, amount, health, minHealth, maxHealth) {\n  // Health changed by ${amount}, now ${health}/${maxHealth}\n});\n\n// Decrease health by 1\nsprite.damage(1);\n\n// Increase health by 2\nsprite.heal(2);\n\n// Set health to 0, only if health \u003e 0\nsprite.kill();\n\n// Set health to 1, only if health \u003c= 0\nsprite.revive();\n\n// Set health to maximum, only if health \u003c= 0\nsprite.reviveAtMaxHealth();\n```\n\nSee the [demo](demo/demo.js) for more example uses.\n\nTests\n-----\n\nOpen [tests](./tests/index.html) in your browser.\n\nAdd\n---\n\n### Browser / UMD\n\nInclude the [UMD script](https://github.com/samme/phaser-component-health/blob/master/dist/phaser-component-health.umd.js) after Phaser and then use the global variable `PhaserHealth`. [The demo](https://codepen.io/samme/pen/BeyZpX) is set up this way.\n\n```html\n\u003cscript src='https://cdn.jsdelivr.net/npm/phaser@3.52.0/dist/phaser.js'\u003e\u003c/script\u003e\n\u003cscript src='https://cdn.jsdelivr.net/npm/phaser-component-health@3.0.0/dist/phaser-component-health.umd.js'\u003e\u003c/script\u003e\n```\n\n### Modules\n\nUse the module's default export:\n\n```js\nimport PhaserHealth from 'phaser-component-health';\n```\n\nAPI\n---\n\n### Static Methods\n\n- PhaserHealth.AddTo(obj, health=1, minHealth=-Infinity, maxHealth=100) → obj\n- PhaserHealth.Damage(obj, amount=1, silent=false) → obj\n- PhaserHealth.Dump(objs) → undefined (see output in console)\n- PhaserHealth.Heal(obj, amount=1, silent=false) → obj\n- PhaserHealth.Kill(obj, silent=false) → obj\n- PhaserHealth.MixinTo(class) → class\n- PhaserHealth.Revive(obj, health=1, silent=false) → obj\n- PhaserHealth.ReviveAtMaxHealth(obj, silent=false) → obj\n- PhaserHealth.SetHealth(obj, health, minHealth, maxHealth, silent=false) → obj\n\n### Actions\n\n- PhaserHealth.Actions.Damage(objs, amount=1, silent=false) → objs\n- PhaserHealth.Actions.Heal(objs, amount=1, silent=false) → objs\n- PhaserHealth.Actions.Kill(objs, silent=false) → objs\n- PhaserHealth.Actions.Revive(objs, health=1, silent=false) → objs\n- PhaserHealth.Actions.ReviveAtMaxHealth(objs, silent=false) → objs\n- PhaserHealth.Actions.SetHealth(objs, health, minHealth, maxHealth, silent=false) → objs\n\n### Component Methods\n\n- damage(amount=1, silent=false) → this\n- getHealth() → number\n- getHealthFrac() → number\n- getMaxHealth() → number\n- getMinHealth() → number\n- heal(amount=1, silent=false) → this\n- isAlive() → boolean\n- isDead() → boolean\n- kill(silent=false) → this\n- revive(health=1, silent=false) → this\n- reviveAtMaxHealth(silent=false) → this\n- setHealth(health, minHealth, maxHealth, silent=false) → this\n- setMaxHealth(maxHealth, silent=false) → this\n- setMinHealth(minHealth, silent=false) → this\n\n### Events\n\n1. `healthchange` → (obj, amount, health, minHealth, maxHealth)\n2. `damage`, `heal` → (obj, amount)\n3. `die`, `revive` → (obj)\n\nThese are also named as\n\n- PhaserHealth.Events.DAMAGE\n- PhaserHealth.Events.DIE\n- PhaserHealth.Events.HEAL\n- PhaserHealth.Events.HEALTH_CHANGE\n- PhaserHealth.Events.REVIVE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamme%2Fphaser-component-health","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamme%2Fphaser-component-health","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamme%2Fphaser-component-health/lists"}