Jump to content

Sprite Objects and Arrays


Shawn
 Share

Recommended Posts

Hi guys! I am having an issue with Sprite objects and arrays, and I bet there is a Phaser-fied way to do what I need, probably using groups, but I don't know what it is (maybe it's just "use groups, duh"):

 

I am making a sample Final Fantasy-like RPG engine, with the following files/objects:

 

Game - Defines player characters, etc.

Play (state) - Defines the over world

Battle (state) - Defines the Final Fantasy-esque battle screen, this is where I create enemies

 

Here is my issue, I create the players in Game - game.player. I create the enemies in Battle - battle.enemy. To make working with them easier, I add them to javascript arrays inside Battle. I have a players array, and an enemies array. But when I attempt to set players.health, it does not update the game.player health, as I would have expected.

 

I suspect I should be adding them to groups or something, but I am unsure.

 

Any help would be awesome, thanks!

 

Shawn

Link to comment
Share on other sites

If this doesn't work, let me know, and I can try and put it up somewhere else. Here is the link to the sample game:  http://shawnmann.com/games/samplerpg/

 

Links to the files:

 

To get to the relevant part in the game, go touch the door to get to the battle scene, then click "Attack" twice with the console open (that will complete a "round" of combat). You can see the health printouts in the console.

 

If that's too much, I can try and replicate it in a simpler project, which might also lead me to a solution. Additionally, I know there is a bunch of superfluous code in the battle.js - most of it are attempts to solve this.

Link to comment
Share on other sites

you are actually hitting testAlly not player.. as game_ids are increasing .. so first actor has - gameID = 1..
and first actor you have created is testAlly

sometimes - I find easier to debug with getters / setters - like in your case it would be somthing like that:

 
var ActorStats = function(actor, health, mana, speed){    this.actor = actor;    this.health = health;    this.mana = mana;    this.speed = speed;};ActorStats.prototype = {    _health: 0,    mana: 0,    speed: 0,    get health(){        return this._health;    },    set health(val){        console.log("Actor with gameID",this.actor.gameID, "got hit by ",(this._health - val));        this._health = val;    }};Actor = function (isEnemy, health, mana, speed) {    this.stats = new ActorStats(this, health, mana, speed);/// rest code here

hope I could help you :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...