0penS0urce Posted June 17, 2015 Share Posted June 17, 2015 I am trying to create an object class, and then make it follow a tween in order to follow a path in a Tower Defense game. However. I get an error: Undefined TypeError : undefined is not a function on the Phaser 2.3 JS file on line 1454. If there is a way to get the object to follow the path, like with physics, please include it and an example. Thanks in Advance! var demoTween;enemy = function(x, y, game){ Phaser.Sprite.call(this, game, x, y, 'enemy'); game.add.tween(this).to({x:800,y:600},5000);}enemy.prototype = Object.create(Phaser.Sprite.prototype);enemy.prototype.constructor = enemy;var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update });function preload(){ game.load.image('enemy', 'assets/player.png');}function create() { var en = enemy(0, 0, game); game.add.existing(en); }function update(){} Link to comment Share on other sites More sharing options...
Skeptron Posted June 17, 2015 Share Posted June 17, 2015 I don't think you should use tweens for characters movements. Tweens are used for animations. Instead you should implement the behaviour of your "enemy" in its update function (check its coords and make him move accordingly). Link to comment Share on other sites More sharing options...
MichaelD Posted June 17, 2015 Share Posted June 17, 2015 The tween can only move in straight lines from x/y to destination x/y. For an actual path with curves you need to implement bezier paths. However I think there is a Phaser plugin that can handle paths, you can view it in this post http://www.html5gamedevs.com/topic/2311-plugin-for-pathfinding-on-maps-using-easystarjs/ Link to comment Share on other sites More sharing options...
Recommended Posts