khleug35

Members
  • Content count

    38
  • Joined

  • Last visited

  1. 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
  2. khleug35

    DEL

    DEL
  3. 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
  4. 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); }
  5. 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 } }
  6. 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 }
  7. 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
  8. Thanks!! samme It work!! but Is it just work for tilemap?? ? Is it working for sprite ?? Thanks
  9. 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; } }
  10. 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.
  11. 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/
  12. Thanks for remind!! I just use photoshop to set the image size , i works for me! Thanks
  13. I use the following example to get start. https://phaser.io/examples/v2/arcade-physics/shoot-the-pointer Is it possible to set the fix point for sprite rotation? Like the following images I try to use sprite..anchor.setTo (0.1,0.5), but not successful, Thanks you very much
  14. Works perfectly!!! You are so awesome!!!Thank you very much and have a nice day!!
  15. I use the following example to get start. https://phaser.io/examples/v2/arcade-physics/shoot-the-pointer When the arrow's angle <= 90 and >= 90, the arrow will stop move and can not shoot to the left!!!! I use the follow code function update() { //right if(sprite.angle <= -90 && sprite.angle >= -180){ sprite.angle=-90; } else if(sprite.angle >= 90 && sprite.angle <= 180){ sprite.angle=90; } //left /* if(sprite.angle >= -90 && sprite.angle <= 0){ sprite.angle = -90; } else if(sprite.angle <= 90 && sprite.angle >= 0){ sprite.angle = 90; } */ } But I hope the bullet not shoot to the left, any idea??? Thanks you so much Here is the jsfiddle link, Thanks https://jsfiddle.net/sjrup0h2/