LuisM

I do not find the error in this code someone help me please

Recommended Posts

I do not find the error in this code anyone help me please.

I'm doing a topdown game but I can not get the camera to follow the sprite player....
Sorry if I'm doing something wrong!
this.Camera.follow (player, Phaser.Camera.FOLLOW_TOPDOWN);
this does not work ! do not open anything; When I remove it everything works normal

var config = {
        type: Phaser.CANVAS,
        width: 1920,
        height: 1080,
        physics: {
            default: 'arcade',
            acarde:{
                //gravity:{ }
                debug: false    
            }
        },
        scene: {
            preload: preload,
            create: create,
            update: update
        }
    };

    var game = new Phaser.Game(config);
    
    
    function preload ()
    {
    this.load.image('ground', 'images/ground-smart.png');
    //pedras
    this.load.image('stone1', 'images/stone-1.png');
    this.load.image('stone5', 'images/stone-5.png');
    //flores
    this.load.image('flor1', 'images/flor1.png');
    this.load.image('flor2', 'images/flor2.png');
    this.load.image('flor3', 'images/flor3.png');
    //player
    this.load.spritesheet('player1', 'images/p-anim.png', { frameWidth: 128, frameHeight: 90 });
    }

    
    function create ()
    {

    this.add.image(960, 540, 'ground');
    this.add.image(64, 430, 'stone1');
    this.add.image(650, 80, 'stone5');
    flores = this.physics.add.staticGroup();
    
    flores.create(400, 350, 'flor1');
    flores.create(220, 90, 'flor3');

    player = this.physics.add.sprite(400, 300, 'player1');

this.Camera.follow(player, Phaser.Camera.FOLLOW_TOPDOWN);


this.anims.create({
    key: 'left',
    frames: this.anims.generateFrameNumbers('player1', { start: 1, end: 7 }),
    frameRate: 6,
    repeat: -1
});

this.anims.create({
    key: 'turn',
    frames: [ { key: 'player1', frame: 0 } ],
    frameRate: 20
});

this.anims.create({
    key: 'right',
    frames: this.anims.generateFrameNumbers('player1', { start: 1, end: 7 }),
    frameRate: 10,
    repeat: -1
});


    cursors = this.input.keyboard.createCursorKeys();
    this.physics.add.collider (player, flores);
    }
    
    
    
    function update ()
    {
        
        if (cursors.up.isDown)
        {
            player.setVelocityY(-160);
            player.anims.play('left', true);
        }
        else if (cursors.down.isDown)
        {
            player.setVelocityY(160);
            player.anims.play('right', true);
        }
        else
        {
            player.setVelocityX(0);
            player.anims.play('turn');
        }

        if (cursors.up.isDown && player.body.touching.down)
        {
            player.setVelocityY(-330);
        }
    }

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.