Jump to content

Uncaught ReferenceError: Phaser is not defined


vmars316
 Share

Recommended Posts

Hello & Thanks ,

Just starting out with Phaser 0.7.0 .

I am running asteroids-movement.js from :

C:\Phaser\phaser-2.4.4\DownloadExamples\phaser-examples-master\examples\arcade-physics\asteroid-movement .

And I am getting the error :

Uncaught ReferenceError: Phaser is not defined(anonymous function) @ asteroids-movement.js:2

Any ideas why ?

asteroids-movement.html looks like this :

Quote

 

    <!doctype html>
    <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
            <title>asteroids-movement.html</title>
            </head>
        <body>
             <script src="asteroids-movement.js" type="text/javascript"></script>
    </body>
    </html>

 

 

 

 

And asteroids-movement.js looks like this :
 

Quote

 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'asteroids-movement', { preload: preload, create: create, update: update, render: render });

function preload() {

    game.load.image('space', 'C:/Phaser/phaser-2.4.4/DownloadExamples/phaser-examples-master/examples/assets/skies/deep-space.jpg');
    game.load.image('bullet', 'C:/Phaser/phaser-2.4.4/DownloadExamples/phaser-examples-master/examples/assets/games/asteroids/bullets.png');
    game.load.image('ship', 'C:/Phaser/phaser-2.4.4/DownloadExamples/phaser-examples-master/examples/assets/games/asteroids/ship.png');

}

var sprite;
var cursors;

var bullet;
var bullets;
var bulletTime = 0;

function create() {

    //  This will run in Canvas mode, so let's gain a little speed and display
    game.renderer.clearBeforeRender = false;
    game.renderer.roundPixels = true;

    //  We need arcade physics
    game.physics.startSystem(Phaser.Physics.ARCADE);

    //  A spacey background
    game.add.tileSprite(0, 0, game.width, game.height, 'space');

    //  Our ships bullets
    bullets = game.add.group();
    bullets.enableBody = true;
    bullets.physicsBodyType = Phaser.Physics.ARCADE;

    //  All 40 of them
    bullets.createMultiple(40, 'bullet');
    bullets.setAll('anchor.x', 0.5);
    bullets.setAll('anchor.y', 0.5);

    //  Our player ship
    sprite = game.add.sprite(300, 300, 'ship');
    sprite.anchor.set(0.5);

    //  and its physics settings
    game.physics.enable(sprite, Phaser.Physics.ARCADE);

    sprite.body.drag.set(100);
    sprite.body.maxVelocity.set(200);

    //  Game input
    cursors = game.input.keyboard.createCursorKeys();
    game.input.keyboard.addKeyCapture([ Phaser.Keyboard.SPACEBAR ]);

}

function update() {

    if (cursors.up.isDown)
    {
        game.physics.arcade.accelerationFromRotation(sprite.rotation, 200, sprite.body.acceleration);
    }
    else
    {
        sprite.body.acceleration.set(0);
    }

    if (cursors.left.isDown)
    {
        sprite.body.angularVelocity = -300;
    }
    else if (cursors.right.isDown)
    {
        sprite.body.angularVelocity = 300;
    }
    else
    {
        sprite.body.angularVelocity = 0;
    }

    if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
    {
        fireBullet();
    }

    screenWrap(sprite);

    bullets.forEachExists(screenWrap, this);

}

function fireBullet () {

    if (game.time.now > bulletTime)
    {
        bullet = bullets.getFirstExists(false);

        if (bullet)
        {
            bullet.reset(sprite.body.x + 16, sprite.body.y + 16);
            bullet.lifespan = 2000;
            bullet.rotation = sprite.rotation;
            game.physics.arcade.velocityFromRotation(sprite.rotation, 400, bullet.body.velocity);
            bulletTime = game.time.now + 50;
        }
    }

}

function screenWrap (sprite) {

    if (sprite.x < 0)
    {
        sprite.x = game.width;
    }
    else if (sprite.x > game.width)
    {
        sprite.x = 0;
    }

    if (sprite.y < 0)
    {
        sprite.y = game.height;
    }
    else if (sprite.y > game.height)
    {
        sprite.y = 0;
    }

}

function render() {
}

 

 

Also , Its been a long time , how do I shorten up this reference Path ?:

    game.load.image('space', 'C:/Phaser/phaser-2.4.4/DownloadExamples/phaser-examples-master/examples/assets/skies/deep-space.jpg'); 

Seems like there should be a "../" in there somewhere ?

Thanks...Vern

Link to comment
Share on other sites

Thanks  ,

after a good nites sleep I realized that .

Now it looks like :         <script src="C:/Phaser/phaser-2.4.4/DownloadExamples/phaser-examples-master/examples/lib/Phaser.js" type="text/javascript"></script>

But now i am getting a diff error :

" asteroids-movement.js:2 Uncaught TypeError: Phaser.Game is not a function "

So I'll start a new Post for that one .

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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