Jump to content

Recommended Posts

Long story short: new to Phaser, making a roguelike.  Turn-based movement on a tilemap grid, etc.

 

Obviously this ground has been covered before, but it seems that every example of a roguelike or RPG that I've found has basically just set the x/y of the sprite every time a movement occurs, and I'd like to be animating it.  I want to wait for user input, then shut off listening for input, and wait for the chosen action/move (if valid) to finish before the game continues processing the turn.  I've got it tweening well, but I'm not sure, conceptually, what the best practice is for "waiting."  A few games I've seen that use turn-based structure set a variable and then check time in update() to see if sufficient time has passed.  I tried using a timer at first, but ran into unexpected behavior (I'm sure I could fix it, but I'm more interested in knowing what I ought to do)...

 

What I have now (experimenting with the former), but not overly enamored with it:

function update() {    if (acceptInput) {        if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {            acceptInput = false;            moveTimer = game.time.time;            game.add.tween(player.body).to({ x: '-' + TILEWIDTH }, MOVEDURATION, Phaser.Easing.Linear.None, true);        } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {            acceptInput = false;            moveTimer = game.time.time;            game.add.tween(player.body).to({ x: '+' + TILEWIDTH }, MOVEDURATION, Phaser.Easing.Linear.None, true);        } else if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {            acceptInput = false;            moveTimer = game.time.time;            game.add.tween(player.body).to({ y: '-' + TILEHEIGHT }, MOVEDURATION, Phaser.Easing.Linear.None, true);        } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {            moveTimer = game.time.time;            acceptInput = false;            game.add.tween(player.body).to({ y: '+' + TILEHEIGHT }, MOVEDURATION, Phaser.Easing.Linear.None, true);        }    }    else     {        if (game.time.time > moveTimer + MOVEDURATION) { acceptInput = true; }    }}

Thoughts?

Link to post
Share on other sites

Excellent feedback! I also noted the use of sprite.input.disable/enable in another thread, which might make my genetic boolean redundant.

As a related followup, how about just waiting for tweens/animation generically? E.g. I have a dozen NPCs to take their returns before I allow player input again. I process the logic for NPC 6, it has to make a series of moves (chaining tweens), then attack (animation), do I set timers or just use appropriate callback functions for each discrete unit of work my objects are doing?

Link to post
Share on other sites

I would use a series of events, not timers, so your game knows exactly which stage it is at, at any given time. So each object would emit an event "taking move", "animating", "scanning", whatever, and you'd have a core game loop that knows what to listen for, in what order and how to make the game advance.

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...