如何在Javascript中缩放Sprite

汉纳克里德

我正在尝试缩放在JavaScript中是子弹的精灵,但它不会改变,我将其放置在错误的函数中吗?它目前位于create函数中,项目符号需要大约10x10 px,但现在它很大,占据了播放屏幕的一半。

我正在使用Phaser.io作为框架,并且尝试了一些缩放方法,但是它似乎不起作用。

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

function preload() {

    game.load.image('bullet', 'Pokeball.png');
    game.load.image('ship', 'assets/sprites/shmup-ship.png');

}

var sprite;
var weapon;
var cursors;
var fireButton;

function create() {
  game.stage.backgroundColor = ('#424242');

    //  Creates 1 single bullet, using the 'bullet' graphic
    weapon = game.add.weapon(1, 'bullet');

    //  The bullet will be automatically killed when it leaves the world bounds
    weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;

    //  Because our bullet is drawn facing up, we need to offset its rotation:
    weapon.bulletAngleOffset = 90;

    //  The speed at which the bullet is fired
    weapon.bulletSpeed = 400;

    sprite = this.add.sprite(320, 500, 'ship');

    game.physics.arcade.enable(sprite);

    //  Tell the Weapon to track the 'player' Sprite, offset by 14px horizontally, 0 vertically
    weapon.trackSprite(sprite, 14, 0);

    cursors = this.input.keyboard.createCursorKeys();

    fireButton = this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR);


    weapon.scale.x = 10;
    weapon.scale.y = 10;

    //  You can also scale sprites like this:
    //  sprite.scale.x = value;
    //  sprite.scale.y = value;



}

function update() {

    sprite.body.velocity.x = 0;

    if (cursors.left.isDown)
    {
        sprite.body.velocity.x = -200;
    }
    else if (cursors.right.isDown)
    {
        sprite.body.velocity.x = 200;
    }

    if (fireButton.isDown)
    {
        weapon.fire();
    }

}

function render() {



}
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Simple Canvas Game</title>
    <style>
      html {
        background: black
      }
      canvas {
        margin: auto;
      }
    </style>
	</head>
	<body>
    <script src="phaser.js"></script>
		<script src="game.js"></script>
	</body>
</html>

测试琪琪

Weapon是一个移相器插件,可帮助您创建项目符号。您可以通过以下方式缩放项目符号:

weapon.bullets.setAll('scale.x', 0.5);
weapon.bullets.setAll('scale.y', 0.5);

在Phaser论坛中发布了类似的问题:http : //www.html5gamedevs.com/topic/30010-euhm-scaling-a-weaponbullets/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章