Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

Image Angle/Rotation Wrong????

$
0
0

Hello fellow HTML5 Game Devs. I have an interesting problem

I am testing out some controls and different schemes for my game. I have an image of a fighter. It uses the arcade physics mode. When I press the UP arrow, it goes right....

Code:


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

function preload() {
    game.load.image('background','../assets/images/deep-space.jpg');
    game.load.image('fighter','../assets/images/Human-Fighter.png');
}

var player;

function create() {

    game.add.tileSprite(0, 0, 1920, 1920, 'background');

    game.world.setBounds(0, 0, 1920, 1920);

    game.physics.startSystem(Phaser.Physics.ARCADE);
    
    player = game.add.sprite(game.world.centerX, game.world.centerY, 'fighter');
    player.anchor.set(0.5, 0.5);

    game.physics.arcade.enable(player);

    //  Notice that the sprite doesn't have any momentum at all,
    //  it's all just set by the camera follow type.
    //  0.1 is the amount of linear interpolation to use.
    //  The smaller the value, the smooth the camera (and the longer it takes to catch up)
    game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1);

}

function update() {
    player.body.velocity.x = 0;
    player.body.velocity.y = 0;
    player.body.angularVelocity = 0;

    if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
        player.body.angularVelocity = -200;
    } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
        player.body.angularVelocity = 200;
    }

    if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
        game.physics.arcade.velocityFromAngle(player.angle, 300, player.body.velocity);
    }
}

function render() {
    
}

 

If you can help, it would be greatly appreciated! Thanks!

Screenshot.jpg


Viewing all articles
Browse latest Browse all 623

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>