Jump to content

Sprite is jumping on resize and drops through platform


Fric
 Share

Recommended Posts

Hello,

i'm trying to make a fighting game, i created an sprite atlas, which has sprites of different frame size. To make Player sprite collision with other player sprite(like kick or punch) i have to resize the player every time, because the player would have a lot of free sprace around him, because of a biggest frame. So now the problem is, that when i resize the sprite, it's jumps (because of the height difference i think) and the worst thing, when i make the animation of the biggest frames, player just drops through  static group platform. I add a mkv file with animation what is happening, can some one help me here?

Code:

 

function preload ()
{
    this.load.image('bg', 'res/namek.jpg');
    this.load.image('ground', 'res/platform.png');
    this.load.atlas('goku', 'res/goku.png', 'res/goku.json');
}

 

function create ()
{
    this.add.image(320, 180, 'bg');

    platforms = this.physics.add.staticGroup();
    platforms.create(320, 320, 'ground');
    platforms.create(120, 320, 'ground');
    platforms.create(520, 320, 'ground');
    platforms.create(-20, 180, 'ground');
    platforms.create(660, 180, 'ground');

    player = this.physics.add.sprite(200, 250, 'goku');

    player.setBounce(0);
    player.setCollideWorldBounds(true);

    this.anims.create({
        key: 'left',
        frames: [ { key: 'goku', frame: 'basic_09' } ],
        frameRate: 20
    });

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

    this.anims.create({
        key: 'right',
        frames: [ { key: 'goku', frame: 'basic_10' } ],
        frameRate: 20
    });

    this.anims.create({
        key: 'block',
        frames: [ { key: 'goku', frame: 'basic_04' } ],
        frameRate: 20
    });

    this.anims.create({
        key: 'right_punch',
        frames: [ { key: 'goku', frame: 'basic_08' } ],
        frameRate: 20
    });

    this.anims.create({
        key: 'right_kick',
        frames: [ { key: 'goku', frame: 'basic_07' } ],
        frameRate: 20
    });

    this.anims.create({
        key: 'power_up',
        frames: this.anims.generateFrameNames('goku', { start: 0, end: 2, zeroPad: 2, prefix: 'basic_' }),
        frameRate: 10,
        repeat: -1
    });

    cursors = this.input.keyboard.createCursorKeys();
    key_z = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
    key_x = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X);

    this.physics.add.collider(player, platforms);
}

 

function update ()
{
    if (cursors.left.isDown) {
        player.setVelocityX(-160);
        player.anims.play('left', true);
        player.setSize(29, 43);
    } else if (cursors.right.isDown) {
        player.setVelocityX(160);
        player.anims.play('right', true);
        player.setSize(32, 41);
    } else if (cursors.shift.isDown) {
        player.anims.play('power_up', true);
        player.setSize(64, 56);
    } else if (cursors.space.isDown) {
        player.anims.play('block');
        player.setSize(24, 48);
    } else if (key_z.isDown) {
        player.anims.play('right_punch');
        player.setSize(32, 44);
    } else if (key_x.isDown) {
        player.anims.play('right_kick');
        player.setSize(40, 45);
    } else {
        player.setVelocityX(0);
        player.anims.play('turn');
        player.setSize(30, 46);
    }

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

dbz-bug.mkv

Link to comment
Share on other sites

I think maybe i should add different anchors for different frame? Will that do the trick? 

About different size frames - well then how am i suppose to make collisions with hits, if my sprite will be the same size? When my sprite making for example kick, it width is more then usual, so the effect of hit collision would be better, don't you agree? 

Link to comment
Share on other sites

1 hour ago, samme said:

Adjust the body offset or position.

Fall-through happens when you enlarge the body and extend the bottom edge through the floor below.

Well i thought there is another way, but ou well, thank you guys!

Link to comment
Share on other sites

I changed pivot point for every smaller sprite like in the biggest sprite and that did the trick. So what i mean is, if i have biggest sprite height of 60px, the pivot point for that sprite is center or in pixels 30px height. Then if i have sprite with height for example 50px, the pivot point height will not be centered, it must be 30px from bottom like in the biggest sprite.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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