strivinglife

Members
  • Content Count

    14
  • Joined

  • Last visited

About strivinglife

  • Rank
    Member

Contact Methods

  • Website URL
    https://jamesrskemp.com
  • Twitter
    strivingllife

Profile Information

  • Gender
    Male
  • Location
    Wisconsin, USA

Recent Profile Visitors

849 profile views
  1. I'm working on a game where I want to do some checks every minute, every five minutes, and then every some amount of seconds (1 and 5 seconds now, but that might change). Right now I'm adding the following in the main game scene: // Add a main timer that runs every second. this.time.addEvent({ delay: 1000, callback: this.doOneSecondActivities, callbackScope: this, loop: true }); // Add a timer that runs every five seconds. this.time.addEvent({ delay: 5000, callback: this.doFiveSecondActivities, callbackScope: this, loop: true }); // Add a timer that should run every minute. this.time.addEvent({ delay: 60000, callback: this.doOneMinuteActivities, callbackScope: this, loop: true }); // Add a timer that should run every five minutes. this.time.addEvent({ delay: 1000 * 60 * 5, callback: this.doFiveMinuteActivities, callbackScope: this, loop: true }); I realize that I shouldn't prematurely optimize, but I'm wondering if I'm going to end up refactoring this later, or if it's relatively safe to setup multiple timers in Phaser 3. (The other way I can think of handling this is to determine what my smallest time is and then manually keep track of the last time the various events were triggered, adding/subtracting time to determine if an interval has passed. Since the game loop can be paused, I do realize that I might still need to check against a timestamp for certain things.) Does anyone have experience with multiple timed events in Phaser 3?
  2. Is this still correct for Phaser 3.12.0? I'm trying the following in TypeScript and it appears both onHidden and onVisible are protected. this.game.events.off("hidden", this.game.onHidden, this.game, false); this.game.events.off("visible", this.game.onVisible, this.game, false);
  3. For what it's worth, doing the following did work: // TypeScript // Creating the animations. for (let i = 1; i <= 13; i++) { for (let j = 1; j <= 19; j++) { this.anims.create({ key: 'stand_monsters_' + i + '_' + j, frames: this.anims.generateFrameNumbers('monsters_' + i + '_' + j, null), frameRate: 5, repeat: -1 }); } } // Calling this when creating the custom objects. this.body.anims.play('stand_monsters_' + style); Is there a recommended best practice on where to setup the animations? Since they're global, that would suggest creating them somewhere that might get called once. For my setup with multiple scenes (with the called order as below), I'm thinking in the Preloader.create() function, instead of where I have it now, instead MainGame.create(). this.scene.add(Boot.Name, Boot); this.scene.add(Preloader.Name, Preloader); this.scene.add(MainMenuScene.Name, MainMenuScene); this.scene.add(MainGame.Name, MainGame);
  4. That makes sense, but each actual Sprite may have a different spritesheet. So I've got my monsters definition (Character doesn't add anything of importance, but extends Phaser.GameObjects.Group, in case it matters), where you can supply the style of monster asset to use. // TypeScript import Character from "./Character"; export default class Monster extends Character { constructor(scene: Phaser.Scene, x: number, y: number, style: string) { super(scene); // The base doesn't actually move at all. var characterBase = this.scene.add.sprite(x, y, 'avatar_1_1'); this.asset = 'monsters_' + style; this.body = this.scene.add.sprite(x, y, this.asset); } } A preloader scene is adding these as: // Load monsters. this.load.path = 'assets/monsters/'; for (let i = 1; i <= 13; i++) { for (let j = 1; j <= 19; j++) { this.load.spritesheet('monsters_' + i + '_' + j, 'monsters_' + i + '_' + j + '.png', { frameWidth: 16, frameHeight: 24 }); } } (Spritesheets are all just two frames.) So I guess that means doing this (the 3.9.0 TS defs don't have a `generateFrameNumbers()` yet for what you've provided, hence the null)? for (let i = 1; i <= 13; i++) { for (let j = 1; j <= 19; j++) { this.anims.create({ key: 'stand', frames: this.anims.generateFrameNumbers('monsters_' + i + '_' + j, null), frameRate: 5, repeat: -1 }); } } That gets me the following, which is what I was expecting to see. So now I'm thinking each sprite needs to have a 'stand' set (`key: 'stand_monsters_' + i + '_' + j`)? Or am I misunderstanding and there's an easier way to write the code? Since you're on the thread, rich, here's more of what I'm trying to convert to Phaser 3, in case it helps with animation usage. // TypeScript - Phaser 2 import { MonsterRarity } from "../Enums"; import Character from "./Character"; export default class Monster extends Character { private monsterBody: Phaser.Sprite; private asset: string; public experience: number; public rarity: MonsterRarity; constructor(game: Phaser.Game, x: number, y: number, style: string) { super(game); // The base doesn't actually move at all. var monsterBase = this.game.add.sprite(x, y, 'avatar_1_1'); monsterBase.anchor.setTo(0.5); this.monsterBody = this.game.add.sprite(x, y, 'monsters_' + style); this.monsterBody.anchor.setTo(0.5); this.monsterBody.animations.add('stand'); this.monsterBody.animations.play('stand', 5, true); this.monsterBody.inputEnabled = true; this.monsterBody.events.onInputDown.add(this.logInfo, this); this.add(monsterBase); this.add(this.monsterBody); // Add this to the game immediately. game.add.existing(this); } logInfo() { console.log(this.monsterBody.key); } }
  5. So, I'm using TypeScript and `this.asset` doesn't appear to be valid. If that's pseudo-code, then I think the issue is that each animated item would have a different asset to pull from.
  6. In Phaser 2 I was able to load a spritesheet and then define a simple animation that would loop through the spritesheet frames. // Defined in the preloader state. this.load.path = 'assets/avatar/'; for (let i = 1; i < 8; i++) { this.game.load.spritesheet('avatar_1_' + i, 'base/avatar_1_' + i +'.png', 16, 24); } // Use the spritesheet when adding the sprite. this.hero = this.game.add.sprite(x, y, 'avatar_1_' + style); // Define an animation and start playing it. this.hero.animations.add('stand'); this.hero.animations.play('stand', 5, true); With Phaser 3 I'm trying to understand how to convert this to the new animations model. // Still loading the spritesheets in the preloader. this.load.path = 'assets/avatar/'; for (let i = 1; i < 8; i++) { this.load.spritesheet('avatar_1_' + i, 'base/avatar_1_' + i +'.png', { frameWidth: 16, frameHeight: 24 }); } // This doesn't appear to have changed much either. this.body = this.scene.add.sprite(x, y, this.asset); // Now I've tried just creating the animation: this.anims.create({ key: 'stand', frameRate: 5, repeat: -1 }); // And then using it on the sprite, but it's complaining about that it: // Cannot read property 'frame' of undefined this.body.anims.play('stand'); Is it still possible to define an animation that just loops through the sprite's spritesheet's frames? If not, do I need to define an animation for every spritesheet I'm using? (Such as in the official Phaser 3 tutorial, https://phaser.io/tutorials/making-your-first-phaser-3-game/part5) Thanks!
  7. Wouldn't you want to handle most of the computations on the server anyway? Once the client reconnects they would get sent the current state of the world.
  8. I completely agree with mazoku. I'm working on a new game and am using Phaser 2 CE. Although now that 3.6.0 dropped with container support I might start looking at using that for pieces of what I'm doing. Being so new, 3 is going to continue changing rapidly, while 2 should be pretty stable.
  9. Does anyone know if the workflow when using NodeJS is going to continue to be npm install phaser --save and then download the TS defs from the https://github.com/photonstorm/phaser3-docs repo? Or might we see the TS defs included as part of the phaser package?
  10. Did you ever come up with a solution for this? I was thinking about something similar this morning, but thought about implementing it by just having hit boxes that would be checked for sequential mouse over.
  11. I agree with the others in that Lazer dev makes more sense since you're doing Pixi in that.
  12. I'm not the OP, but I found this as well. this.game.state.start('Preloader', true, false);The way I move between states is given above (for example, the above is in my Boot state). I got hung up briefly the first time I ran into this, but then I figured the load manager was probably for the entirety of the game, so it makes sense it would persist between state changes.
  13. Found this linked to from another thread and found it very useful. FYI, based upon the official photon storm plugin TypeScript definition, the constructor accepts a Phaser.Game and Phaser.PluginManager. constructor(game:Phaser.Game, parent: Phaser.PluginManager);
  14. Hello. I'm looking at the example under Debug Display on the official site, at http://phaser.io/examples/v2/debug/debug-display Within the render() there's the following call: game.debug.spriteCorners(sprite, true, true);Unfortunately, I don't see that this actually exists. Is it safe to assume that this example just contains an out of date call, or am I missing something? Thanks! James