Mickety

Members
  • Content count

    34
  • Joined

  • Last visited

  1. Platformer game collision problem

    I think the collision box is a little wider. Try moving right and jumping BEFORE you hit the wall. Once you do, character will hit a ceiling, that is not there. Hope this gives you some insight.
  2. How to set body Size on group for each sprite?

    Wouldn't balnk_platform.callAll('body.setSize', '', 300, 300, 0, 0); work as well? Anyways It's great that you found your own solution
  3. Spawning sprites randomly for endless runner

    why not use Phaser.Math.random() ? It can be used as a range between numbers like Phaser.Math.random(-20,250)
  4. Any idea how to stop object from flickering

    Don't "snap" the clock hands to time right away, when you move them. Snap them to realtive measurements when you release the mouse button. That's all I can say at this point, maybe someone more skilled will tell you how to fix this more easily.
  5. Spawning sprites randomly for endless runner

    Start with a timer function and an array that stores your obstacles in the UPDATE cycle. And with this we've created an obstacle generator. You can also add Phaser.Math.random(0,64) to x and/or y position of an obstacle for randomness Next we need to manage the obstacles I bet phaser group collision can do a better job here though but you'll have to read up on it yourself, because I don't know much about it. Hope it helps.
  6. Is there a way to only detect one key press?

    var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.background.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true); this.player.animations.play('run', 10, true); // logo this.splash = this.add.sprite(this.game.world.centerX, this.game.world.centerY - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if ( this.game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR)) { this.game.state.start('gamePlay'); } } }; var gamePlay = function(game) {}; gamePlay.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 2000; // background this.background = this.game.add.tileSprite(0, -30, this.game.width, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 310, this.game.width, 60, 'sprites', 'ground'); this.ground.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true); this.player.animations.play('right', 10, true); // physics on sprites this.game.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; this.player.body.collideWorldBounds = true; //add spacebar for jump this.jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); }, update: function () { // look for collisions between sprites this.game.physics.arcade.collide(this.player, this.ground); //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving right if (cursors.right.isDown) { this.player.body.velocity.x = 90; this.player.animations.play('right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90; this.player.animations.play('right'); } // jump //if (this.jumpButton.isDown && (this.player.body.touching.down)) { if( this.game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR) && this.player.body.touching.down ) { this.player.body.velocity.y = -800; } } }; var gameOver = function(game) {}; gameOver.prototype = { preload: function() { //preloading assets game.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text this.game.add.text(this.game.world.centerX - 100, this.game.world.centerY + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if (this.game.input.activePointer.justPressed()) { this.game.state.start('mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu');
  7. Is there a way to only detect one key press?

    while we on the subject I fixed spacebar just pressed by the code provided. I tested it, it has to work. Here you go. code taken from this thread:
  8. Would it be easier to learn Phaser 2 for a beginner?

    I'd stick to phaser 2 CE for now. Even though quite hypocritically I regret not learning phaser 3 since I've gotten much better at reading docs while learning Phaser 2.
  9. I am glad it helped. I'm also glad the message was sent, because right after I posted than response my internet went down
  10. Is there a way to only detect one key press?

    You don't need anything but "justPressed" So instead of if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR) && keyDown == false) { keyDown = true; game.state.start('GamePlay'); } if (game.input.keyboard.justReleased(Phaser.Keyboard.SPACEBAR)) { keyDown = false; } Just put this: if (game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR)) { game.state.start('GamePlay'); } "justPressed" has an in-built switch for button press, so you don't really need any "keyDown" and stuff.
  11. Well once a computer (or anything for that matter) connects to a WiFi network it gets it's own inner IP address. Usually your router IP is something like "192.168.1.1" (at least if you have a wire connecting router to PC directly). Any other device will have an IP like "192.168.1.31" or "192.168.1.45" My phone for example has a 192.168.1.38 IP address, so if I were to run a web-server on it I could connect to it via that IP address if my PC was connected to the same WiFi router. Basically all you need to do is: -Have two PCs (or similar devices) connected to the same WiFi network -Run a webserver (apache, nginx or many others) on one of them -Figure out the LOCAL IP (like "192.168.1.41) of the device that is running a webserver (you can do this by directly connecting to your wifi router. It usually has a list of devices with their names and addresses) -Put the local IP address in a browser tab and voila. If your ISP is generous enough and router can be easily configured you'd also be able to access it from outside the WiFi network.
  12. You can always run a local web-server on your WiFi network. Any computer will do, I have a Raspberry Pi for all my webdev mobile testing needs. My ISP even provides internet access to my webserver over IP so I can access it for testing from far away. Alternatively (although somewhat illegal I guess) you can look into a thing called "Hackintosh" where you emulate MacOS for debugging purpose. It's a drag, sure, but I don't see any other way. Apple is not exactly known for, well, "friendliness" in that regard.
  13. Yes I've heard about this too. Luckily no dynamic resizing stuff or even mobile support is expected anywhere in the nearest future, so I can get away with just html tags. Thanks for the insight.
  14. A sound advice. I am used to using HTML elements over canvas for games as UI, but I always had thoughts like "What if that is a really silly thing to do but I don't know about it? What if it lowers performance greatly?" Well with answers given in this thread I have a direction to move toward to. Thank you.
  15. Hello @onlycape thanks for the insight. That seems to be the case. What if my game is fullscreen though and I don't intend on porting it to mobile devices?