Phaser纹理图集错误的尺寸

时间:2018-02-27 13:30:28

标签: javascript phaser-framework

我在游戏中使用了spritesheets,但我遇到了一个问题,我希望我的角色能够躲避子弹(躲避子弹)。我发现我可以使用纹理图集。基于我所读到的,我想,这种方法将根据其当前动画调整精灵的大小。因此,当我躲开时,精灵会改变它的高度,因为用于躲避的框架比用于站立的框架要低。

我加载地图集如:

game.load.atlasJSONHash('player', '../assets/images/player/player.png', '../assets/images/player/player.json');

我可以看到json中的尺寸是正确的,闪避框架的高度是31,站立是51.

"duck-right": {
            "frame": {
                "x": 20,
                "y": 0,
                "w": 19,
                "h": 31
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 19,
                "h": 31
            },
            "sourceSize": {
                "w": 19,
                "h": 31
            }
        },
"right": {
            "frame": {
                "x": 100,
                "y": 71,
                "w": 19,
                "h": 51
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 19,
                "h": 51
            },
            "sourceSize": {
                "w": 19,
                "h": 51
            }
        }

我像这样创建我的播放器:

export default class Player extends Phaser.Sprite {
constructor({ game, x, y }) {
    super(game, x, y, 'player')
    game.physics.arcade.enable(this)
    this.body.bounce.y = 0
    this.body.gravity.y = 1200
    this.body.collideWorldBounds = true
    this.state = game.state.getCurrentState()
    this.anchor.setTo(0.5,1)

    //custom properties
    this.direction = 'left'
    this.isJumping = false
    this.isDucking = false
    this.isShooting = false
    this.isOnGround = false
    this.speed = 150
    this.lives = 2
    this.jumpSpeed = 350
    this.isInElevator = false
    this.activeElevator = null

    // set up animations
    //stand still
    this.animations.add('left', ['left'], 10, false)
    this.animations.add('right', ['right'], 10, false)
    //walk
    this.animations.add('go-left', ['go-left-1', 'go-left-2'], 10, true)
    this.animations.add('go-right', ['go-right-1', 'go-right-2'], 10, true)
    //shoot
    this.animations.add('shoot-left', ['shoot-left'], 1, false)
    this.animations.add('shoot-right', ['shoot-right'], 1, false)
    //duck
    this.animations.add('duck-left', ['duck-left'], 1, false)
    this.animations.add('duck-right', ['duck-right'], 1, false)
    //duck shoot
    this.animations.add('duck-shoot-left', ['duck-shoot-left'], 1, false)
    this.animations.add('duck-shoot-right', ['duck-shoot-right'], 1, false)
    //jump
    this.animations.add('jump-left', ['jump-left'], 1, false)
    this.animations.add('jump-right', ['jump-right'], 1, false)
    //jump shoot
    this.animations.add('jump-shoot-left', ['jump-shoot-left'], 1, false)
    this.animations.add('jump-shoot-right', ['jump-shoot-right'], 1, false)

    console.log(this.body)

    game.add.existing(this)
}

但是动画的高度并没有改变。确实如此,但不正确。锚(0.5,1)也不起作用,就像我躲避时一样,我躲在精灵区的顶部,而不是底部。

尝试使用TexturePacker或其他方法,修剪与否,总是相同的结果。你能否至少证实它能像我期待的那样发挥作用?例如。锚应该工作,精灵应该根据当前帧改变其尺寸?

0 个答案:

没有答案