Jump to content

Physics Frustrations with 2.0


RyanTheBoy
 Share

Recommended Posts

Hey All,

 

So I put a lot of time into this code and happily found it doesn't work in Phaser 2.0; instead it now throws the error...

 

TypeError: this.game.physics.angleToPointer is not a function

 

I don't want to write this all over again(though I may not have a choice), so I thought I would post the code here to see if anyone could suggest a simple solution. I could roll back to version 1.1.6 for now but that would be a little cheaty I suppose.

 

Anyway, here is the source.

 

(Essentially, this would make my Cat by drawing the body and the head. The head would angle toward the mouse and the puke would spray based on the angle to it. Without the .angleToPointer() function it is entirely broken.)

 

Cat.JS

Cat = function(game) {    this.game = game;    this.catGrp = null;    this.catState = null;    this.catPuke = null;};var torso = null;var head = new Array(3);var pivotPt = null;var launchPt = null;var REG = 0;var SICK = 1;var PUKING = 2;Cat.prototype = {    create: function() {        // Create a group to store all of the cat based sprites.        this.catGrp = this.game.add.group();        // The torso is the base of the cat and is stationary,        // thus it is placed first at the bottom of the cat        // stack.        torso = this.catGrp.create(this.game.world.width / 2, this.game.world.height / 2, 'cat', 'torso0');        // Wag the cat's tail.        torso.animations.add('wag', ['torso0', 'torso1', 'torso2', 'torso3', 'torso2', 'torso1'], 10, true);        torso.animations.play('wag');        // The head[] array will hold all of the cats various        // heads. The update function in turn will use for loops        // to update them all synchronously.        head[0] = this.catGrp.create(torso.x + 35, torso.y, 'cat', 'head0');        head[0].anchor = new Phaser.Point(0.8, 0.9);        head[1] = this.catGrp.create(torso.x + 45, torso.y + 7, 'cat', 'head1');        head[1].anchor = new Phaser.Point(0.7, 0.9);        head[2] = this.catGrp.create(torso.x + 45, torso.y + 7, 'cat', 'head2');        head[2].anchor = new Phaser.Point(0.7, 0.7);        // Place the pivot point(pivotPt so the we can mathemagically        // ensure the puke is coming out of the puking head's(head[2])        // mouth. The emitter's(this.catPuke) position is set to (0, 0)        // initially and will be moved during the update function based        // on where the head is aiming.          pivotPt = new Phaser.Point(head[2].x, head[2].y);        // this.catState will be used to poll for whether or not the cat        // is idle(REG), charging its puke(SICK), or launching its vom        // (PUKING). Later the game will manage these states based on how        // well the player performs during the charging stage.        this.catState = PUKING;        this.catPuke = this.game.add.emitter(0, 0);        this.catPuke.makeParticles('testPuke', 0, 100, true, false);        //this.catPuke.start(false, 0, 50);    },    update: function() {        for (var i = 0; i < 3; i++) {            head[i].alpha = 0;            head[i].rotation = this.game.physics.angleToPointer(head[i]) + Math.PI;            if (head[i].angle >= 25) head[i].angle = 25;            else if (head[i].angle <= -15) head[i].angle = -15;        }        this.catPuke.x = pivotPt.x - 30 * Math.cos(head[2].angle * Math.PI / 180);        this.catPuke.y = pivotPt.y - 30 * Math.sin(head[2].angle * Math.PI / 180);        var xRay = -(Math.abs(this.catPuke.x - pivotPt.x));        var yRay = -(pivotPt.y - this.catPuke.y);        this.catPuke.setXSpeed(5 * xRay, 10 * xRay);        this.catPuke.setYSpeed(5 * yRay, 10 * yRay);        if (this.catState == REG) {            head[0].alpha = 1;        }        if (this.catState == SICK) {            head[1].alpha = 1;        }        if (this.catState == PUKING) {            head[2].alpha = 1;            if (!this.catPuke.on) this.catPuke.start(false, 0, 50);        }    },    render: function() {        this.game.debug.renderSpriteBounds(head[2]);        this.game.debug.renderPoint(pivotPt);        //this.game.debug.renderPoint(launchPt);    }};

 

-Ryan

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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