ekeimaja

[SOLVED] Why my game doesn't appear?

Recommended Posts

var RPG_test = RPG_test || {};

RPG_test.game = new Phaser.Game(640,640, Phaser.AUTO, 'game');

RPG_test.game = function () {

};

RPG_test.game.prototype = {
    preload: function () {

        this.game.load.image('street', 'img/street.png', 980, 860);
        this.game.load.image('player', 'img/human.png', 50, 50);

    },
    create: function () {
        
        this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.cursors = this.game.input.keyboard.createCursorKeys();
        
        this.game.add.sprite(0, 0, 980, 860, 'street');
        this.player = this.game.add.sprite(400, 400, 'player');
        this.game.world.setBounds(0, 0, 980, 860);
        this.game.physics.p2.enable(this.player);
        this.game.camera.follow(this.player);
        

    }

When I try to run that, game area appears just black.

Share this post


Link to post
Share on other sites

You are overwriting your game immediately after you create it. Notice how you set RPG_test.game to an empty function right after you create your new game.

RPG_test.game = new Phaser.Game(640,640, Phaser.AUTO, 'game');

RPG_test.game = function () {

};

 

Share this post


Link to post
Share on other sites

Alright, so it looks like you are trying to create a state object that you want your game to use.

You will need to create your game separately and add your state object to your game. Something like this:

var RPG_test = RPG_test || {},
    game = new Phaser.Game(640,640, Phaser.AUTO, 'game');

RPG_test.game = function (game) {

        this.game = game;

};

RPG_test.game.prototype = {
    preload: function () {

        this.game.load.image('street', 'img/street.png', 980, 860);
        this.game.load.image('player', 'img/human.png', 50, 50);

    },
    create: function () {
        
        this.game.physics.startSystem(Phaser.Physics.P2JS);
        this.cursors = this.game.input.keyboard.createCursorKeys();
        
        this.game.add.sprite(0, 0, 980, 860, 'street');
        this.player = this.game.add.sprite(400, 400, 'player');
        this.game.world.setBounds(0, 0, 980, 860);
        this.game.physics.p2.enable(this.player);
        this.game.camera.follow(this.player);
        

    }
};

// The name of the state doesn't matter too much. The last argument, true, automatically starts the new state
game.state.add('RPG_test', RPG_test.game, true);

Note that I didn't test this, but this should be enough to get you in the right direction. If there are any small errors like syntax issues, the console will tell you.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.