Jump to content

Tweening several times is causing a jerking motion, am I doing something wrong?


Waizujin
 Share

Recommended Posts

As this video here shows, when I press and hold up it tweens fine for a few tiles (16x16 tiles) then it starts to jerk back and forth like some kind of horror movie. Video: http://screencast.com/t/WtYheCRSAO7E

 

I'm unsure what is causing this, but I want my character to move 1 tile (16x16 tiles) smoothly for the moving animation. If I do it 1 button press at a time like at the end of the video it's fine, otherwise it does the jerking motion. I'm sure this is just how my code is setup, or perhaps I shouldn't be using tweens at all, however I'm new to all of this and about 20 minutes of googling hasn't found me a solution. :(

 

So here is my code, any help you can provide would be greatly appreciated! Btw, the code might look kind of stupid how I do a few things, I was just trying random things to see if it would work haha.

var game = new Phaser.Game(640, 480, Phaser.AUTO, 'gameDiv', { preload: preload, create: create, update: update, render: render });var map;var layer;var player;var move;var isMoving = false;function preload() {    game.load.tilemap('Test', 'asset/Test.json', null, Phaser.Tilemap.TILED_JSON);    game.load.image('Tiles', 'asset/Tilesets/basictiles_2.png');    game.load.image('player', 'asset/character.png');}function create(){    game.stage.backgroundColor = '#ffffff';        map = game.add.tilemap('Test');    map.addTilesetImage('BasicTiles', 'Tiles');    layer = map.createLayer('Ground');    layer = map.createLayer('Trees');    layer.resizeWorld();        player = game.add.sprite(game.world.centerX, game.world.centerY, 'player');}function update(){    move = game.add.tween(player);        if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))    {        player.x -= 16;    }    else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))     {        player.x += 16;    }    else if (game.input.keyboard.isDown(Phaser.Keyboard.UP))    {        moveUp();    }    else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))    {        player.y += 16;    }}function render(){    game.debug.text('move.isRunning:' + move.isRunning);}function moveUp(){    if (isMoving === false)    {        isMoving = true;        move.to( { y: player.y - 16 }, 300).start();        isMoving = false;    }}
Link to comment
Share on other sites

I've seen worse horror movies!

 

Your update method will be calling MoveUp() everytime the key is held down.  As the isMoving flag apprears to always be false, it serves no protection so move.to() will always be called - and Phaser doesn't like that if it's already mid-tween.

 

Either:

1. fix your isMoving protection

2. kill a running tween before starting another

3. don't try to tween if already running

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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