razetime Posted April 15, 2020 Share Posted April 15, 2020 I am a Phaser beginner. I have created a spline path as per the example given here: http://phaser.io/examples/v3/view/paths/curves/spline-curve I want to make an image/ sprite follow the spline path with variable acceleration given by the user. How do I do this? Code: create() { //loop below statements for each car this.car = this.add.image(50, 400, 'car'); //TODO: make a car class this.car.rotation = Math.PI / 2; this.createVectors(); this.track = new Curves.Spline(this.trackPath); this.path = { t: 0, vec: new PhaserMath.Vector2() }; } update() { this.graphics.clear(); this.graphics.lineStyle(5, 0x5f0f40, 1); this.track.draw(this.graphics, 64); this.track.getPoint(this.path.t, this.path.vec); this.car.x = this.path.vec.x; this.car.y = this.path.vec.y; this.graphics.fillStyle(0xff0000, 1); this.graphics.fillCircle(this.path.vec.x, this.path.vec.y, 8); } Link to comment Share on other sites More sharing options...
Recommended Posts