khleug35

Members
  • Content Count

    111
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by khleug35

  1. 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 } }
  2. 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 }
  3. 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
  4. Thanks!! samme It work!! but Is it just work for tilemap?? ? Is it working for sprite ?? Thanks
  5. 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; } }
  6. Oh!!!Thank you for your help and guidance !! Your code is clear and efficient.
  7. 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/
  8. Thanks for remind!! I just use photoshop to set the image size , i works for me! Thanks
  9. 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
  10. Works perfectly!!! You are so awesome!!!Thank you very much and have a nice day!!
  11. 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/
  12. How to get the Sprites that is different position and size on Spritesheet?? Thx I want to get this "the Biggest dude" on this image use phaser and without use scale method function preload() { game.load.spritesheet('dude', 'assets/dude.png',32,48); } function create() { player = game.add.sprite(100, 200, 'dude'); player.animations.add('left', [0, 1, 2, 3], 10, true); player.animations.add('right', [5, 6, 7, 8], 10, true); //the dude become bigger, but I have no idea how to set it player.animations.add('Big', [?????], 10, true); } function update() { player.animations.play('Big'); } I want to get this "the Biggest dude" in the image bottom, it width is 72 and height is 72, Thanks you very much.
  13. Thanks!!!! It works!!! thanks 3man7!!!! thank you for your help!!! you are awesome, Thanks
  14. Happy New Years every one. I use this sample to create some game that the user can use their mouse to change the gun direction https://phaser.io/examples/v2/arcade-physics/angle-to-pointer I use the gun image to replace the arrow.png image I hope when the object rotate to left or right ,the image(gun) can reverse like the following image. The following image is when the pointor go to the top left Here is my Script: var sprite; var faceRight = false; var faceLeft = true; //I try to use the follow script to fix the sprite postion if(sprite.angle <= 90 && sprite.angle >= -90){ console.log("Right"); if (faceLeft == true) { sprite.scale.y *= -1; sprite.anchor.y = 0.5; faceLeft = false; faceRight = true; } }else{ console.log("Left"); if (faceRight == true) { sprite.scale.y *= -1; sprite.anchor.y = 0.5; faceRight = false; faceLeft = true; } } But not successful, The following image is my fail example, any idea how to do it?? thx Thanks you very much, I am sorry for my pool English.
  15. thanks for reply I using ogg and mp3 ....... I try to convert this example to android apk file https://phaser.io/examples/v2/audio/play-music It also can't run the game about audio error......... when I use this code game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']); but I use this code ,it is work game.load.audio('boden', ['http://examples.phaser.io/assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'http://examples.phaser.io/assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']); I find that phonegap can't play local audio...... but this audio problem just occurs on android
  16. hello ,thank you for reply. I used Adobe PhoneGap, but when I build the game to apk file and run it on android It can't play the audio , I need to use phonegap media api to instead of Phaser audio code...... and I run the game on the android platform below 5.0 versions, It is very lag................ It is run very prefect on browser and IOS,^_^ thx
  17. Hello, everyone Which software do you recommend to build the phaser game for mobile? I used Adobe phonegap build to convert the game for moblie.......but any other suggestion?? How about react native?? THX
  18. Thank you very much!!!!samme, thank you for your help!!!!!!!!! i am sorry about that i am so stupid......... ,but thank you for your help!!!!
  19. THX, samme this code is work for me !!! thx but I am sorry about that, I have an other problem now..... I want to change state on timer........... the following code is not work, did I made a mistake?? Thank you so much this.time.events.add(Phaser.Timer.SECOND * 4, this.game.state.start('gameover'), this);//not work this.time.events.add(Phaser.Timer.SECOND * 4, this.game.state.start, this, 'gameover');//not work this.time.events.add(Phaser.Timer.SECOND * 4, this.game.state.start, 'gameover');//not work this.time.events.add(3000, this.state.start, this, ['gameover']);//not work
  20. Could I code for a function in timer.events directly?? here is my code Normally ,The following code is work for me!!!!!!! game.time.events.add(Phaser.Timer.SECOND * 4, player_kill, this); function player_kill() { player.kill(); } but Is it possible to code for a function in timer.events directly??? THX Maybe like this , but the following code is not work, did I made a mistake?? Thank you so much game.time.events.add(Phaser.Timer.SECOND * 4, player.kill(), this); //not work
  21. here is my code <script> var game = new Phaser.Game(372, 635, Phaser.AUTO, 'game'); game.state.add('menu',menu); game.state.add('Level1',Level1); game.state.start('menu'); </script> //Level1.js var Level1 = { init: function() { this.play = true; <---------/*I want to call it in Enemy: function(){this.init = function()*/--> }, preload: function() { this.load.im.......... }, create: function() { this.enemy = new this.Enemy(); this.enemy.init(); }, update: function() { ........ }, Enemy: function(){ this.init = function (){ console.log(this.play); <-----------/*I want to call this.play = true, but it show undefined*/ if(this.play == true){ <-----------/*I want to call this.play = true, but it show undefined*/ dosomething..... }else{ dosomething..... } } I want to call "this.play = true; " in Enemy: function(){ this.init = function () but it is not successful......the chrome console is display show "undefined" How is it possible to call this function??? thx very much
  22. OH!!!! Thanks!!!!When i update to Phaser CE 2.8.8!!!! It worked for me!!!!! https://phaser.io/download/stable Thanks!!!!!!samme!!!!!!