Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Phaser from 'phaser-ce';
- import Utils from './game/utils';
- var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload, create, update });
- var player;
- var cursors;
- function preload() {
- game.load.spritesheet('dude', 'assets/chars/cowboy.png', 129, 129 );
- }
- function create() {
- player = game.add.sprite(32, game.world.height - 150, 'dude');
- game.physics.arcade.enable(player);
- player.body.collideWorldBounds = true;
- console.log(Utils.rangeAnimation( (2-1)*14 ,7 ));
- // this display : [14, 15, 16, 17, 18, 19, 20]
- console.log(Utils.rangeAnimation( (1-1)*14 ,7 ));
- // [0, 1, 2, 3, 4, 5, 6]
- console.log(Utils.rangeAnimation( (6-1)*14 ,7 ));
- //[70, 71, 72, 73, 74, 75, 76]
- player.animations.add('left', Utils.rangeAnimation((2-1)*14,7) , 14, true);
- player.animations.add('right', Utils.rangeAnimation((1-1)*14 ,7) , 14, true);
- player.animations.add('up', Utils.rangeAnimation( (6-1)*14 ,7 ) , 14, true);
- // player.animations.add('bottom', Utils.rangeAnimation(14*9 ,7), 7, true);
- cursors = game.input.keyboard.createCursorKeys();
- }
- function update() {
- player.body.velocity.x = 0;
- player.body.velocity.y = 0;
- if (cursors.left.isDown)
- {
- player.body.velocity.x = -150;
- player.animations.play('left');
- }
- else if (cursors.right.isDown)
- {
- player.body.velocity.x = 150;
- player.animations.play('right');
- }
- else if (cursors.up.isDown)
- {
- player.body.velocity.y = -50;
- player.animations.play('up');
- }
- else if (cursors.down.isDown)
- {
- player.body.velocity.y = 50;
- player.animations.play('bottom');
- }
- else
- {
- player.animations.stop(null,true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment