Jump to content

Update function on external classes


Ynozzar
 Share

Recommended Posts

Hi everyone!

 

So I'm having some issues regarding the update function. Let me explain myself;

 

I've got a GameState class, in which the game runs. Then, for example, I add player turrets via a Turret class that extends Sprite. And then I add an TurretDeployer (which doesn't extend anything) class that is responsible of spawning the Turret objects.

 

But, while the Turret objects self-update, the TurretDeployer one doesn't. I have to explicitly add the TurretDeployer.update(); code into the GameState update loop.

 

Now I created a TurretUpgrader class (also extends nothing), that handles upgrading the turrets from Turret class, and it does nice if I 'hardcode' it into the GameState, while using TurretUpgrader.update(). But, if I add the both Turret and TurretUpgrader with the TurretDeployer class, TurretUpgrader won't launch the update loop.

 

 

I hope I made myself clear enough.

Thanks a lot beforehand!

 

 

 

PD: I've searched for this around the forums and found nothing. If there's an answer already there, my apologies.

Link to comment
Share on other sites

Hi,

 

Thanks a lot for the reply. No, I don't have it that way. Actually, I can not have it that way, since I create the Turret objects "on demand" with, for example, a button. That way, there's new Turret and TurretUpgrader objects for each turret deployed, and so I can't access them via variable name. I use TypeScript, therefore I don't know how well you will understand my code, but here is the turret creation function;

 

private deployTurretStatic():void{

// Deploy both the turret and the upgrader. Upgrader gets the turret
// in the create() function as a parameter.
var newTurret:TurretStatic;
var newUpgrader:TurretUpgrader;
newTurret = new TurretStatic(this.game'static_1'this.deployX510);
newUpgrader = new TurretUpgrader(this.gamenewTurret);

// Add the turret to the world and enable physics.
GameState.s_gameState.worldContainer.addChild(newTurret);
this.game.physics.enable(newTurretPhaser.Physics.ARCADE);

}

 

 

One more time, thanks beforehand!

Link to comment
Share on other sites

Hi Ynozzar,

 

Your create object on demande (so there is more than one ? )

Maby you can put all this on demand created object on an array and then do

 

class TurretDeployer

   update: ->
      for on_demande in TurretUpgrader.on_demande_objects
         on_demande.update()

 

 

Then you have a dynamic update for dynamic object.

 

Side Question:

why Typescript rather than js or coffee ?

Typed language didn't slow you down ? it look like c or java.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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