Ynozzar Posted December 18, 2014 Share Posted December 18, 2014 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 More sharing options...
rtlehr Posted December 18, 2014 Share Posted December 18, 2014 Do you haveTurretUpgrader.update()in theTurretDeployer.update()function? Something Like thisTurretDeployer.prototype.update = function(){ TurretUpgrader.update();} Link to comment Share on other sites More sharing options...
Ynozzar Posted December 18, 2014 Author Share Posted December 18, 2014 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.deployX, 510);newUpgrader = new TurretUpgrader(this.game, newTurret);// Add the turret to the world and enable physics.GameState.s_gameState.worldContainer.addChild(newTurret);this.game.physics.enable(newTurret, Phaser.Physics.ARCADE);} One more time, thanks beforehand! Link to comment Share on other sites More sharing options...
rtlehr Posted December 18, 2014 Share Posted December 18, 2014 Yeah, I don't know TypeScript at all, but my thought is that somewhere, TurretUpgrader.update(); needs to be called, I'm just not sure from where. Sorry I can't help more. Ross Link to comment Share on other sites More sharing options...
Ynozzar Posted December 18, 2014 Author Share Posted December 18, 2014 Well, thanks a lot anyway. My concern is actually more oriented to how to make the class call the update function itself, as the ones that extend from Sprite do. Thanks beforehand one more time! Link to comment Share on other sites More sharing options...
ranska Posted December 19, 2014 Share Posted December 19, 2014 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 More sharing options...
Recommended Posts