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 その6

Posted at

概要

Plunkerで、Phaser.Physicsやってみた。
applyForceで、力を加えてみた。

写真

image.png

サンプルコード


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 
    create: create, 
    update: update,
    render: render 
});
function create() {
    game.stage.backgroundColor = '#124184';
    game.physics.startSystem(Phaser.Physics.BOX2D);
    game.physics.box2d.gravity.y = 400;
    game.physics.box2d.restitution = 0.8;
    game.physics.box2d.setBoundsToWorld();
    for (var i = 0; i < 10; i++)
    {
        var ball = new Phaser.Physics.Box2D.Body(this.game, null, game.world.randomX, 0);
        ball.setCircle(16);
        ball.bullet = true;
    }
    cart = new Phaser.Physics.Box2D.Body(this.game, null, game.world.centerX, 243);
    cart.setRectangle(60, 20, 0, 0, 0);
    cart.mass = 1;
    cursors = game.input.keyboard.createCursorKeys();
}
function update() {
    if (cursors.up.isDown) 
    {
        cart.applyForce(0, -10);
    }
    if (cursors.left.isDown) 
    {
        cart.applyForce(-5, 0);
    }
    if (cursors.right.isDown) 
    {
        cart.applyForce(5, 0);
    }
}
function render() {
    game.debug.box2dWorld();
}




成果物

以上。

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?