0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PlunkerでPhaser.Physics その8

Posted at

概要

Plunkerで、Phaser.Physicsやってみた。
spriteInfo、使ってみた。

写真

image.png

サンプルコード

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 
    preload: preload, 
    create: create, 
    update: update, 
    render: render 
});
function preload() {
    game.load.image('arrow', 'assets/sprites/arrow.png');
}
var sprite;
function create() {
    game.physics.startSystem(Phaser.Physics.ARCADE);
    game.stage.backgroundColor = '#0072bc';
    sprite = game.add.sprite(400, 300, 'arrow');
    sprite.anchor.setTo(0.5, 0.5);
    game.physics.enable(sprite, Phaser.Physics.ARCADE);
}
function update() {
    sprite.body.velocity.x = 0;
    sprite.body.velocity.y = 0;
    sprite.body.angularVelocity = 0;
    if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
    {
        sprite.body.angularVelocity = -200;
    }
    else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
    {
        sprite.body.angularVelocity = 200;
    }
    if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
    {
        game.physics.arcade.velocityFromAngle(sprite.angle, 300, sprite.body.velocity);
    }
}
function render() {
    game.debug.spriteInfo(sprite, 32, 32);
    game.debug.text('angularVelocity: ' + sprite.body.angularVelocity, 32, 200);
    game.debug.text('angularAcceleration: ' + sprite.body.angularAcceleration, 32, 232);
    game.debug.text('angularDrag: ' + sprite.body.angularDrag, 32, 264);
    game.debug.text('deltaZ: ' + sprite.body.deltaZ(), 32, 296);
}




成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?