Jump to content

Search the Community

Showing results for tags 'phaser-2.4.6'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. I'm creating a "arena" survival game, and have many AI tanks that follow and attack the player. I'm extending the Sprite object for all of my game "entities". I'm using TimerEvents fairly frequently to automatically update different aspects of each enemy. My problem is, once I spawn even a small number of enemies (20-30ish), the number of TimerEvents in the main game timer starts to rise since each tank has around 3 TimerEvents to itself. I've realized having a TimerEvent for every single aspect of the tank seems to be slowing down my game, but I can't see a better alternative. A couple partial examples of what I'm using them for (the "FREQ" delays are 100ms): move(direction: MoveDirection) { this.moveTimer = this.tankSprite.game.time.events.loop(TankMoveManager.CHECK_DIRECTION_FREQ, () => this.updateVelocity(direction), this); this.moveDirection = direction; } private updateVelocity(direction: MoveDirection) { if (direction === MoveDirection.NOT_MOVING) return; let angle = direction === MoveDirection.FORWARD ? this.tankSprite.angle : TankMoveManager.reverseAngle(this.tankSprite.angle); this.tankSprite.body.velocity = this.tankSprite.game.physics.arcade.velocityFromAngle(angle, this.moveVelocity); } This is a part of every tank Sprite, including the player. Since tanks can really only move forward, I'm having the tank move forward, and periodically adjusting the velocity to account for the angle that it's facing. startAttacking() { if (this.firingTimer != null) { return; } this.host.setFiringAngle(null); this.firingTimer = this.host.game.time.events.loop(AlignedShotManager.DIRECTION_UPDATE_FREQ, () => { let angleToTarget = Phaser.Math.radToDeg(this.host.game.physics.arcade .angleToXY(this.host, this.target.x, this.target.y)); if (Math.abs(this.host.angle - angleToTarget) < AlignedShotManager.TARGET_ANGLE_EPSILON) { this.host.startFiring(); } else { this.host.stopFiring(); } }, this); } This is in every enemy tank. It periodically checks if it's facing the target (the player), and starts firing if it is. startFiring() { if (!this.firingTimer) { let shotDelay = this.gunProperties.delayBetweenShots; this.fireBullet(); this.firingTimer = this.game.time.events.loop(shotDelay, () => this.fireBullet(), this); } } This is a part of the Gun class, which is also a part of every tank. I'm using the timer to continually fire bullets until it's told to stop firing. All of the above methods have a "stop" variant that removes the TimerEvent from the Timer, and handles any cleanup. After testing, I've made sure I'm not leaking TimedEvents. What can I do to prevent the number of TimerEvents from exploding and plugging up the Timer? I thought of having a single TimerEvent per tank, and just adding new tasks on by chaining the callback, but that prevents me from stopping a single task; I could only kill all the tasks in the callback or none at all (I couldn't stop firing but continue moving). Any guidance here would be greatly appreciated.
×
×
  • Create New...