khleug35

Members
  • Content count

    41
  • Joined

  • Last visited

  1. khleug35

    how to do this effect ?

    Hello I just add this scale code, but I not sure that is it the best way to do it.........sorry arrow.scale.setTo(-1); Example: https://jsfiddle.net/r37qdpvn/
  2. khleug35

    how to do this effect ?

    like this??? https://jsfiddle.net/1sje65a0/5/ function create() { game.stage.backgroundColor = '#000'; arrow = game.add.image(90, 36, 'arrow'); widtharrow = new Phaser.Rectangle(0, 0,arrow.width, arrow.height); arrow.cropEnabled = true; arrow.crop(widtharrow); arrow.fixedToCamera = true; widtharrow.width = 0; game.time.events.loop(800, function() { game.add.tween(widtharrow).to( { width: (widtharrow.width + 60) }, 200, Phaser.Easing.Linear.None, true); }, this); } function update() { arrow.updateCrop(); //loop animations if(widtharrow.width >= 300){ game.add.tween(widtharrow).to( { width: (widtharrow.width - arrow.width) }, 200, Phaser.Easing.Linear.None, true); } } I use crop method to do it . https://phaser.io/examples/v2/sprites/horizontal-crop
  3. Hello everyone, I would like to create a player, when user press spacebar ,the player is shooting right and left at the same time. But I don't know is it a stupid way to code this?? The full code and eample , spacebar is shooting button, Is it ??? https://jsfiddle.net/8q95wdv1/ Create Two Group //right shoot bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; bullets.createMultiple(40, 'bullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true); //left shoot bullets2 = game.add.group(); bullets2.enableBody = true; bullets2.physicsBodyType = Phaser.Physics.ARCADE; bullets2.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; function fire() { if (game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); bullet2 = bullets2.getFirstExists(false); if (bullet && bullet2) { //right bullet.reset(player.body.x, player.body.y ); bullet.lifespan = 2000; bullet.body.velocity.x = 1000; //left bullet2.reset(player.body.x, player.body.y ); bullet2.lifespan = 2000; bullet2.body.velocity.x = -1000; bulletTime = game.time.now + 250; } } } var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render:render}); var player; var cursors; var shootButton; var bulletTime = 0; function preload() { game.stage.backgroundColor = '#ffffff'; game.load.baseURL = 'http://examples.phaser.io/assets/'; game.load.crossOrigin = 'anonymous'; game.load.image('player', 'sprites/phaser-dude.png'); game.load.image('platform', 'sprites/platform.png'); game.load.image('bullet', 'games/invaders/enemy-bullet.png'); } function create() { player = game.add.sprite(350, 200, 'player'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; cursors = game.input.keyboard.createCursorKeys(); shootButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); player.customParams = {}; //right shoot bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; bullets.createMultiple(40, 'bullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('outOfBoundsKill', true); bullets.setAll('checkWorldBounds', true); //left shoot bullets2 = game.add.group(); bullets2.enableBody = true; bullets2.physicsBodyType = Phaser.Physics.ARCADE; bullets2.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; bullets2.createMultiple(40, 'bullet'); bullets2.setAll('anchor.x', 0.5); bullets2.setAll('anchor.y', 0.5); bullets2.setAll('outOfBoundsKill', true); bullets2.setAll('checkWorldBounds', true); } function update () { game.physics.arcade.collide(player); player.body.velocity.x = 0; if (cursors.left.isDown || player.customParams.isMovingLeft) { player.body.velocity.x = -250; } if (cursors.right.isDown || player.customParams.isMovingRight) { player.body.velocity.x = 250; } if (shootButton.isDown) { fire(); } } function fire() { if (game.time.now > bulletTime) { bullet = bullets.getFirstExists(false); bullet2 = bullets2.getFirstExists(false); if (bullet && bullet2) { //right bullet.reset(player.body.x, player.body.y ); bullet.lifespan = 2000; bullet.body.velocity.x = 1000; //left bullet2.reset(player.body.x, player.body.y ); bullet2.lifespan = 2000; bullet2.body.velocity.x = -1000; bulletTime = game.time.now + 250; } } } function render() { } Thank you very much!!!!
  4. Here it full code https://jsfiddle.net/93q4z560/ I use the following link for template https://phaser.io/examples/v2/category/buttons When I create more than one button and test it on mobile device or chrome toggle device mode. When I click the button2 and hold it move it button 1, It work, button1 is over. But Button1 is still "over", not "Out" so when I second time to click the button2 and hold it move it button 1, It work, button1 is over. it still over how to set onscreen button over to out directly, THX if(button2.events.onInputOut{ button1.events.onInputOver = false; button1.events.onInputOut = true; } Thank you very much
  5. khleug35

    DEL

    DEL
  6. khleug35

    [Solved]About Resize the sprite

    OH!!!!!Many Thanks It is very simple way to solve my problem I am sorry that I am so stupid.... thank you very much
  7. khleug35

    [Solved]About Resize the sprite

    Here is my full code of the example. https://jsfiddle.net/8ytsozsm/1/ I would like to create a platformer game and make the player has crouch function but It has a problem , When I click the down button to resize the sprite to achieve "crouch" if (cursors.down.isDown) { player.body.setSize(60, 89, 0, 0); } else{ player.body.setSize(60, 130, 0, 0); } the sprite is resize from from bottom to top, but I hope the sprite can resize from the top , how to do it with out player.scale.y = -1; player.scale.y = -1; this code can solve my problem, but Is there any other better way to do it? thank you so much, thx var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update ,render: render}); var player; var platforms; var cursors; var jumpButton; function preload() { game.stage.backgroundColor = '#131314'; game.load.baseURL = 'http://examples.phaser.io/assets/'; game.load.crossOrigin = 'anonymous'; /*game.load.image('player', 'sprites/phaser-dude.png');*/ game.load.image('platform', 'sprites/platform.png'); game.load.image('platform2', 'sprites/platform.png'); game.load.tilemap('tilemap', 'https://hexus.github.io/phaser-arcade-slopes/assets/maps/demo.json', null, Phaser.Tilemap.TILED_JSON); } var player; var platforms; var cursors; var jumpButton; function create() { player = game.add.sprite(100, 100); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y = 500; platforms = game.add.physicsGroup(); platforms.create(500, 150, 'platform'); platforms.create(-200, 300, 'platform'); platforms.create(400, 450, 'platform'); platforms.setAll('body.immovable', true); cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); } function update () { game.physics.arcade.collide(player, platforms); player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -250; } else if (cursors.right.isDown) { player.body.velocity.x = 250; } if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) { player.body.velocity.y = -400; } if (cursors.down.isDown) { player.body.setSize(60, 89, 0, 0); } else{ player.body.setSize(60, 130, 0, 0); } } function render () { game.debug.body(player); }
  8. Here is my full code of the example. https://jsfiddle.net/d7p7upso/4/ First, I prepared two image, One for main character , one for On Screen control Button 1. 2. I hope I can do that When User click and hold on the "DOWN" button or Green Button The sprite will hold crouch image like this But unlucky...... The sprite is looping the sprite Anyone have idea how to make the spite complete his animation and hold it in last frame??? Thank you very much , I am sorry for my pool english var game = new Phaser.Game(500, 300, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update}); var crouchFlag = false; function preload() { game.stage.backgroundColor = '#85b5e1'; game.load.spritesheet('player', 'assets/crouch.png',45,65); game.load.image('button', 'assets/HitBoxButton.png'); } function create() { player = game.add.sprite(100, 100, 'player'); player.customParams = {}; cursors = game.input.keyboard.createCursorKeys(); crouchAnim = player.animations.add('crouch', [0, 1, 2, 3], 10, false); crouchAnim.onComplete.add(function () { crouchFlag = false; }); Button1 = game.add.button(game.width - 200, game.height - 120, 'button'); Button1.scale.setTo(0.5); Button1.events.onInputDown.add(function(){ player.customParams.isCrouch = true; }, this); Button1.events.onInputOver.add(function(){ player.customParams.isCrouch = false; }, this); Button1.events.onInputUp.add(function(){ player.customParams.isCrouch = false; }, this); Button1.events.onInputOut.add(function(){ player.customParams.isCrouch = false; }, this); } function update () { if (cursors.down.isDown || player.customParams.isCrouch) { crouchFlag = true; } else{ } console.log(crouchFlag); if (crouchFlag) { player.animations.play('crouch'); } else{ player.frame = 4 } }
  9. Is it a clever way to stop and avoid looping the sprite animation ? The following is my code function update(){ if (cursors.down.isDown) { crouch = true; if(crouch){ player.animations.play('crouch'); //set the time to aviod the animation looping game.time.events.add(Phaser.Timer.SECOND * 0.12, this.animations_Stop, this); } } if (cursors.down.isUp) { crouch = false; } } function animations_Stop () { player.animations.paused = true; // stop the animation }
  10. Is Joystick Plugin: Dpad possible to achieve the player move to 8 direction?? update: function () { var maxSpeed = 300; if (this.stick.isDown) { this.sprite.body.velocity.set(0); if (this.stick.direction === Phaser.LEFT) { this.sprite.body.velocity.x = -maxSpeed; } else if (this.stick.direction === Phaser.RIGHT) { this.sprite.body.velocity.x = maxSpeed; } else if (this.stick.direction === Phaser.UP) { this.sprite.body.velocity.y = -maxSpeed; } else if (this.stick.direction === Phaser.DOWN) { this.sprite.body.velocity.y = maxSpeed; } //8 direction movement else if (this.stick.direction === Phaser.UP && this.stick.direction === Phaser.LEFT) { this.sprite.body.velocity.x = -maxSpeed; this.sprite.body.velocity.y = -maxSpeed; } else if (this.stick.direction === Phaser.UP && this.stick.direction === Phaser.RIGHT) { this.sprite.body.velocity.x = maxSpeed; this.sprite.body.velocity.y = -maxSpeed; } else if (this.stick.direction === Phaser.Down && this.stick.direction === Phaser.LEFT) { this.sprite.body.velocity.x = -maxSpeed; this.sprite.body.velocity.y = maxSpeed; } else if (this.stick.direction === Phaser.Down && this.stick.direction === Phaser.RIGHT) { this.sprite.body.velocity.x = maxSpeed; this.sprite.body.velocity.y = maxSpeed; } } else { this.sprite.body.velocity.set(0); } } Thanks
  11. Thanks!! samme It work!! but Is it just work for tilemap?? ? Is it working for sprite ?? Thanks
  12. Is it possible to create steep path without NINJA PHYSICS? make the player stand on oblique platform or steep path and the player will slip down, Thank you very much https://jsfiddle.net/0z76tofy/ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update}); var player; var platforms; var cursors; var jumpButton; function preload() { game.stage.backgroundColor = '#85b5e1'; game.load.baseURL = 'http://examples.phaser.io/assets/'; game.load.crossOrigin = 'anonymous'; game.load.image('player', 'sprites/phaser-dude.png'); game.load.image('platform', 'sprites/platform.png'); game.load.image('platform2', 'sprites/platform.png'); } function create() { player = game.add.sprite(100, 100, 'player'); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y = 500; platforms = game.add.physicsGroup(); platforms.create(-100, 200, 'platform'); platforms.setAll('body.immovable', true); cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); } function update () { game.physics.arcade.collide(player, platforms); platforms.angle = 20; player.body.velocity.x = 0; if (cursors.left.isDown) { player.body.velocity.x = -250; } else if (cursors.right.isDown) { player.body.velocity.x = 250; } if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) { player.body.velocity.y = -400; } }
  13. khleug35

    Is this a smart way to code the player slash function?

    Oh!!!Thank you for your help and guidance !! Your code is clear and efficient.
  14. Hello everyone, I would like to create a platform game like Castlevania. Here is my full code of the example. This following code can achieve the slash effect, but I do not know is this a smart way?? Thanks https://jsfiddle.net/4m3uv052/ First, I prepared two image, One for main character , one for slash. The last position of slash.png is blank The purpose is when finish slash.png animation, the slash.png will disappear, no residue slash.animations.add('slash_attack', [0, 1, 2, 3 ,4], 20, false); Firstly, Make the slash not visible. If I make the slash image visible, when I run the game, it will show on game. slash.visible = false; Add the player slash logic in function update() if (player_sword_attack == false) { if (attackButton.isDown) { player_sword_attack = true; } } if (player_sword_attack == true) { attack(); game.time.events.add(Phaser.Timer.SECOND * 0.2, attack_stop, this); } fix the slash effect positon function attack() { slash.animations.play('slash_attack'); slash.body.x = sprite.body.x-5; //fix the slash effect positon slash.body.y = sprite.body.y-36; } function attack_stop() { player_sword_attack = false; } is this a smart way to code the player slash function? i am sorry for my poor english? Thank you very much https://jsfiddle.net/4m3uv052/
  15. Thanks for remind!! I just use photoshop to set the image size , i works for me! Thanks