khleug35

Members
  • Content Count

    111
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by khleug35

  1. khleug35

    DEL

    Sorry,It is my mistake Yesterday ,I tried to update and edit the question on my phone. I deleted the entire post accidentally, so I need to ask this question again. sad
  2. Thank you for your tutorial, very detail and helpful!!
  3. @Wolfsbane awesome !!! it work!!!!! Thank you very much for the awesome code and teaching me!!! Have a nice day!!! Thanks again!!!
  4. My Full code game.module( 'game.main' ) .require( ) .body(function() { game.addAsset('logo.png'); game.createScene('Main', { init: function() { this.world = new game.Physics(); this.world.gravity.y = 0; this.Box1 = new game.Box1(220,800); this.Box1.sprite.addTo(this.stage); this.Box2 = new game.Box2(game.width/2,game.height/2); this.Box2.sprite.addTo(this.stage); this.Box1Text = new game.SystemText(''); this.Box1Text.position.set(100,100); this.Box1Text.size = 36; this.Box1Text.addTo(this.stage); this.Box2Text = new game.SystemText(''); this.Box2Text.position.set(100,150); this.Box2Text.size = 36; this.Box2Text.addTo(this.stage); } }); game.createClass('Box1', { init: function(x, y) { this.body = new game.Body(); this.body.collisionGroup = 1; this.body.collideAgainst.push(2); this.body.position.set(x, y); this.body.collide = this.collide.bind(this); this.sprite = new game.Sprite('logo.png'); this.sprite.anchorCenter(); var shape = new game.Rectangle(this.sprite.width, this.sprite.height); this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); }, collide: function(body) { if (body.collisionGroup === 2) { game.scene.Box1Text.text = 'Box1 is connect'; } return true; }, update: function() { if (game.keyboard.down('RIGHT')) { this.body.velocity.x = 250; } else if (game.keyboard.down('LEFT')) { this.body.velocity.x = -250; }else if (game.keyboard.down('UP')) { this.body.velocity.y = -250; }else if (game.keyboard.down('DOWN')) { this.body.velocity.y = 250; }else { this.body.velocity.set(0,0); } this.sprite.position.copy(this.body.position); } }); game.createClass('Box2', { init: function(x, y) { this.body = new game.Body(); this.body.collisionGroup = 2; this.body.collideAgainst.push(1); this.body.position.set(x, y); this.body.collide = this.collide.bind(this); this.sprite = new game.Sprite('logo.png'); this.sprite.anchorCenter(); var shape = new game.Rectangle(this.sprite.width, this.sprite.height); this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); }, collide: function(body) { if (body.collisionGroup === 1) { game.scene.Box2Text.text = 'Box2 is connect'; } return true; }, update: function() { if (game.keyboard.down('D')) { this.body.velocity.x = 250; } else if (game.keyboard.down('A')) { this.body.velocity.x = -250; }else if (game.keyboard.down('W')) { this.body.velocity.y = -250; }else if (game.keyboard.down('S')) { this.body.velocity.y = 250; }else { this.body.velocity.set(0,0); } this.sprite.position.copy(this.body.position); } }); }); When user keydown the "UP or DOWN or RIGHT, or LEFT" key can move the Box1 Class When Box1 move to Box2 body and they are colliding. The Box1text is show " Box1 is connect" collide: function(body) { if (body.collisionGroup === 2) { game.scene.Box1Text.text = 'Box1 is connect'; } return true; }, and Box2text is show " Box2 is connect", collide: function(body) { if (body.collisionGroup === 1) { game.scene.Box2Text.text = 'Box2 is connect'; } return true; }, but only Box1text successful show the text. I have set collide: function to box1.class and box2.class, what is the problem game.createClass('Box1', { .......... this.body.collisionGroup = 1; this.body.collideAgainst.push(2); this.body.collide = this.collide.bind(this); .......... collide: function(body) { if (body.collisionGroup === 2) { game.scene.Box1Text.text = 'Box1 is connect'; } return true; }, .......... }); game.createClass('Box2', { .......... this.body.collisionGroup = 2; this.body.collideAgainst.push(1); this.body.collide = this.collide.bind(this); }, collide: function(body) { if (body.collisionGroup === 1) { game.scene.Box2Text.text = 'Box2 is connect'; } return true; }, .......... Please don't use the following method //the following code is Work, but I don't use this method ,thanks you very much game.createClass('Box1', { .......... this.body.collisionGroup = 1; this.body.collideAgainst.push(2); this.body.collide = this.collide.bind(this); .......... collide: function(body) { if (body.collisionGroup === 2) { game.scene.Box1Text.text = 'Box1 is connect'; game.scene.Box2Text.text = 'Box2 is connect'; } return true; }, .......... }); Thank you very much!!!!!!
  5. @enpu Thank you for your help , It work!!!!!!
  6. game.createScene('Main', { gravity: 2100, init: function() { this.world = new game.Physics(); this.world.gravity.y = this.gravity; ...... }); game.createClass('Bird',{ ....... this.body.velocityLimit.y = 1; //It can make the sprite prevent gravity ...... }); I use this code to make some sprite prevent gravity this.body.velocityLimit.y = 1; but I think this is not best way to solve problem. the sprite can't move to y position any idea?? Thanks
  7. save game localStorage.setItem("item-key", "item data"); get save data localStorage.getItem("item-key"); delete save localStorage.removeItem("item-key");
  8. Oh, Many Thank you for your help @Wolfsbane Finally I work on it !!!!!!!! Really Really Thanks !!!!!!!! firstly I added this code on player class collide: function(body, dir) { if (body.collisionGroup === 2) { this.onPlatform = true; // default is false this.myPlatform = body; }else{ this.onPlatform = false; } and add this code on float platform update function update: function() { if (game.scene.player.onPlatform) { game.scene.player.body.position.x -= ( this.float_platformer.position.x - this.body.position.x); } this.float_platformer.position.x = this.body.position.x; this.float_platformer.position.y = this.body.position.y; } It work!!!! Thanks again, for the help on this , have a nice day
  9. Hello everyone, I am beginner of panda2. I would like to create a platformer game like Kuru Panda, so I download panda2-template-platformer.zip to start my project. and want to create a float platform that can move right to left or left to right on game like the following demo 2:26 but I am not successful to create that, the player can't move when drive on the float platform game.createClass('Float_platformer', { init: function() { this.float_platformer = new game.Sprite('float_platformer.png'); this.float_platformer.anchorCenter(); this.float_platformer.addTo(game.scene.container); this.body = new game.Body(); this.body.mass = 0; this.body.position.x = 1260; this.body.position.y = 1460; this.body.collisionGroup = 2; var shape = new game.Rectangle(); shape.width = this.float_platformer.width; shape.height = this.float_platformer.height; this.body.addShape(shape); this.body.static = true; this.body.addTo(game.scene.world); game.Tween.add(this.body.position, { x: 1560 }, 2000, { easing: 'Quadratic.InOut', repeat: Infinity, yoyo: true }).start(); }, update: function() { this.float_platformer.position.x = this.body.position.x; this.float_platformer.position.y = this.body.position.y; } }); game.createClass('Player', { ..... collide2: function(other) { if (other.collisionGroup === 2) { this.body.velocity.x = 200; } }, .... )}; any tips or idea??? Thank you very much
  10. I think that he means Multi-Touch. right?? @BillyKane My case: the joystick of movement control on left hand side, the shoot button on right hand side of screen. when I hold movement joystick and touch the ''shoot button" on mobile. it have an effect on movement control. My solution is disable joystick's mousedown function on right hand side of screen. (but I’m Not Sure Is it the best way to solve the problem) open the joystick.js file , and try this code on update update: function() { if(game.input.mouse.x < 550){ if (!this.active) return; var angle = this._mouseDownPos.angle(game.input.mouse); var dist = this._mouseDownPos.distance(game.input.mouse); var radius = this.bg.shapes[0].shape.radius / 2; if (dist > radius) dist = radius; this.pad.position.x = Math.cos(angle) * dist; this.pad.position.y = Math.sin(angle) * dist; this.axis.x = this.pad.position.x / radius; this.axis.y = this.pad.position.y / radius; } }
  11. I solved this, I modified Player class update function movement code, it worked😀, thx @enpu if (game.keyboard.down('LEFT') || joystick.axis.x < 0) { this.body.velocity.x = -this.walkSpeed; } else if (game.keyboard.down('RIGHT') || joystick.axis.x > 0) { this.body.velocity.x = this.walkSpeed; } else{ this.body.velocity.x = 0; } if (game.keyboard.down('UP') || joystick.axis.y < 0) { this.body.velocity.y = -this.walkSpeed; } else if (game.keyboard.down('DOWN') || joystick.axis.y > 0) { this.body.velocity.y = this.walkSpeed; } else { this.body.velocity.y = 0; }
  12. Thx. @enpu I added it but still not work, I try to add the following code this.body.velocity.x += game.scene.joystick.axis.x * 200 * game.delta; this.body.velocity.y += game.scene.joystick.axis.y * 200 * game.delta; the player still not move , anyidea? thanks
  13. Hello,Everyone, I download 'RPG' Game template on this link https://www.panda2.io/templates and would like to add Virtual Joystick plugin on this game firstly, I add the Virtual Joystick plugin code on main.js and add the shoot button the following is shoot button code: //player shoot button code var player = this.player; this.shotbutton = new game.Graphics(); this.shotbutton.drawCircle(50, 50, 50); this.shotbutton.x = 550; this.shotbutton.y = 850; this.shotbutton.alpha = 0.5 this.shotbutton.addTo(this.stage); this.shotbutton.interactive=true; this.shotbutton.click=function(){ player.shoot(); }; this code is work!!! the player can shoot arrow but I try to add the Virtual Joystick plugin , it seem not work....... I add the following code on game.createScene 'Main' , init function game.createScene('Main', { init: function() { ... this.joystick = new game.Joystick(150, game.height - 150, 120, 'red'); this.joystick.addTo(this.stage); ... }); and add the following code on game.createClass('Player', 'Animation', , update function game.createClass('Player', 'Animation', { walkSpeed: 200, health: 5, shield: false, ... update: function() { this.body.velocity.x += joystick.axis.x * walkSpeed * game.delta; this.body.velocity.y += joystick.axis.y * walkSpeed * game.delta; ... } }); but the player is not move.......,any idea or tip how to active the plugin ?? thank you very much
  14. @enpu 👐, I love you so much !!!!!!!!!!!!!!!!!thanks for this
  15. OH!!!!!It work!!! Thank you very much!! Have a nice day ,Thanks
  16. I would like to create some platform game, when the player jumps through the enemy, the enemy will face the player automatically. https://jsfiddle.net/sm80pwgt/3/ I try to find the solution, but I think it is not good method if (player.x > 340) { enemy.scale.x = -1; }else{ enemy.scale.x = 1; } My full code var game = new Phaser.Game(780, 500, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update}); var crouchFlag = false; function preload() { game.stage.backgroundColor = '#85b5e1'; game.load.image('enemy', 'http://i.imgur.com/VKpkHXz.png'); game.load.image('player', 'http://examples.phaser.io/assets/sprites/phaser-dude.png'); game.load.image('platform', 'http://examples.phaser.io/assets/sprites/platform.png'); } function create() { player = game.add.sprite(100, 200, 'player'); enemy = game.add.sprite(390, 410, 'enemy'); enemy.anchor.setTo(0.5,0.5); game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.body.gravity.y = 800; platforms = game.add.physicsGroup(); platforms.create(0, 450, 'platform'); platforms.create(400, 450, 'platform'); platforms.setAll('body.immovable', true); cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); jumpButton2 = game.input.keyboard.addKey(Phaser.Keyboard.UP); } 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 = -600; } /* if (player.x > 340) { enemy.scale.x = -1; }else{ enemy.scale.x = 1; } /* } Thank you very much!!!!!!!
  17. 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/
  18. 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
  19. 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!!!!
  20. 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
  21. khleug35

    DEL

    DEL
  22. OH!!!!!Many Thanks It is very simple way to solve my problem I am sorry that I am so stupid.... thank you very much
  23. 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); }