karneekarnay

Members
  • Content Count

    7
  • Joined

  • Last visited

Everything posted by karneekarnay

  1. I've dabbled with HTML5 for a while now and I'm continuously surprised with what HTML5 and Javascript can achieve now. It's got me thinking why we don't see things like Call of Duty/Halo'esq or Grand Strategy games like CK2 using the language? Are we still restricted by technical limits or is it just the lack of adoption from the wider Games Industry?
  2. Midway through writing this saying that I think you've got it right I realised wtf went wrong. KIDS. LET THIS BE A LESSON TO YOU ALL. NEVER COPY AND PASTE FROM THE TUTORIAL UNLESS YOU HAVE TO. The issue was that my code was place the sprites underground... The container var worked fine. It was just that because I've been trying to make the code work with a template I made earlier, I made changes the differed from the tutorial, so the Y & X placements were completely off. I fixed up the function, changed the x & y and it worked fine. @michebn I wouldn't have got here without you. Cheers bud.
  3. Thanks michebn. The moveblock was my attempt to solve an earlier problem. If I attempt to combine the make & make functions into one, as per the tutorial. makeBlocks() { this.blocks.removeAll(); this.wallHeight=this.game.rnd.integerInRange(1, 4); this.wallPosition=this.blockOffset(); for (var i = 0; i < this.wallHeight; i++) { this.block = this.game.add.sprite(this.wallPosition, (this.game.height-89)-i * 25 , "block"); this.blocks.add(this.block); } this.blocks.x = this.game.width - this.blocks.width this.blocks.y = this.ground.y - 50; // //Loop through each block //and apply physics var container = this; this.blocks.forEach(function(block) { //enable physics container.game.physics.enable(block, Phaser.Physics.ARCADE); //set the x velocity to -160 block.body.velocity.x = -150; //apply some gravity to the block //not too much or the blocks will bounce //against each other block.body.gravity.y = 4; //set the bounce so the blocks //will react to the runner block.body.bounce.set(1, 1); }); } I am unable to create the sprites or if I do, I can't see them. The tutorial want's the function to look like this: makeBlocks() { this.blocks.removeAll(); this.wallHeight=this.game.rnd.integerInRange(1, 4); this.wallPosition=this.blockOffset(); for (var i = 0; i < this.wallHeight; i++) { this.block = this.game.add.sprite(this.wallPosition, (this.game.height-89)-i * 25 , "block"); this.blocks.add(this.block); } this.blocks.x = this.game.width - this.blocks.width this.blocks.y = this.ground.y - 50; // //Loop through each block //and apply physics this.blocks.forEach(function(block) { //enable physics this.game.physics.enable(block, Phaser.Physics.ARCADE); //set the x velocity to -160 block.body.velocity.x = -150; //apply some gravity to the block //not too much or the blocks will bounce //against each other block.body.gravity.y = 4; //set the bounce so the blocks //will react to the runner block.body.bounce.set(1, 1); }); } Note the var container line and it's reference is gone. When I do this, I get complaints about the this.game.physics.enable(block, Phaser.Physics.ARCADE); line. Specifically that the game object can't be found. Any ideas?
  4. Hi Guys, I'm following the tutorial to create an Endless Runner game in Phaser (Link Here) I've followed the tutorial so far, but for whatever reason the blocks I've added that should be moving towards the player, will not move. Here is my game code below: /*global Phaser*/ class Game extends Phaser.State { preload() { this.style = { font: "30px Courier", fill: "#000", boundsAlignH: "center", boundsAlignV: "middle" }; this.loadingLabel = this.game.add.text(this.game.world.centerX, this.game.world.centerY, "loading...",this.style); this.loadingLabel.anchor.setTo(0.5); } create() { // A simple background for our game this.game.add.sprite(0, 0, 'sky'); // The platforms group contains the ground and the 2 ledges we can jump on this.platforms = this.game.add.group(); // We will enable physics for any object that is created in this group this.platforms.enableBody = true; // Here we create the ground. this.ground = this.platforms.create(0, this.game.world.height - 64, 'ground'); // Scale it to fit the width of the game (the original sprite is 400x32 in size) this.ground.scale.setTo(2, 2); this.power = 0; //add the hero in this.hero = this.game.add.sprite(32, this.game.world.height - 89, "hero"); //add the power bar just above the head of the hero this.powerBar = this.game.add.sprite(this.hero.x + 25, this.hero.y - 25, "star"); this.powerBar.width = 0; //start the physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); //enable the hero for physics this.game.physics.enable(this.hero, Phaser.Physics.ARCADE); this.game.physics.enable(this.ground, Phaser.Physics.ARCADE); this.hero.body.gravity.y = 200; this.hero.body.collideWorldBounds = true; //this.hero.body.bounce.set(0, 0.2); // This stops it from falling away when you jump on it this.ground.body.immovable = true; //record the initial position this.startY = this.hero.y; //set listeners this.game.input.onDown.add(this.mouseDown, this); this.blocks = this.game.add.group(); this.makeBlocks(); } update() { this.game.physics.arcade.collide(this.hero, this.ground); // //collide the hero with the blocks // this.game.physics.arcade.collide(this.hero, this.blocks); // //colide the blocks with the ground // this.game.physics.arcade.collide(this.ground, this.blocks); // //when only specifying one group, all children in that //group will collide with each other // this.game.physics.arcade.collide(this.blocks); // //get the first child var fchild = this.blocks.getChildAt(0); //if off the screen reset the blocks if (fchild.x < -this.game.width) { this.moveBlocks(); } } mouseDown () { if (this.hero.y != this.startY) { return; } this.game.input.onDown.remove(this.mouseDown, this); this.timer = this.game.time.events.loop(Phaser.Timer.SECOND / 1000, this.increasePower, this); this.game.input.onUp.add(this.mouseUp, this); } mouseUp () { this.game.input.onUp.remove(this.mouseUp, this); this.doJump(); this.game.time.events.remove(this.timer); this.power = 0; this.powerBar.width = 0; this.game.input.onDown.add(this.mouseDown, this); } increasePower() { this.power++; this.powerBar.width = this.power; if (this.power> 50) { this.power = 50; } } doJump() { this.hero.body.velocity.y = -this.power * 12; } makeBlocks() { this.blocks.removeAll(); this.wallHeight=this.game.rnd.integerInRange(1, 4); this.wallPosition=this.blockOffset(); for (var i = 0; i < this.wallHeight; i++) { this.block = this.game.add.sprite(this.wallPosition, (this.game.height-89)-i * 25 , "block"); this.blocks.add(this.block); } } moveBlocks() { this.blocks.x = this.game.width - this.blocks.width this.blocks.y = this.ground.y - 50; // //Loop through each block //and apply physics var container = this; this.blocks.forEach(function(block) { //enable physics container.game.physics.enable(block, Phaser.Physics.ARCADE); //set the x velocity to -160 block.body.velocity.x = -150; //apply some gravity to the block //not too much or the blocks will bounce //against each other block.body.gravity.y = 4; //set the bounce so the blocks //will react to the runner block.body.bounce.set(1, 1); }); } blockOffset() { return this.hero.x + 100; } } The important part is the moveBlocks() function. that's where it should be moving the blocks, but it's not. Also is there a cleaner way to refer to the original object instead of using a contrainer var?
  5. I've been updating my base projects in-line with ECMA2015 standard. There is a lot of good stuff I really enjoy in this. I think the use of classes really makes code more easy on the eyes and easier to manager. I've created a base project using the Basic Game example tutorial using some of the new stuff. BasicPhaserGameECMA2015 I've not setup the menu or gameover states, but that should be simple enough. Hope you guys get some use out of it.
  6. Hi Guys, I have a Phaser Group called enemies that I have so far populated with enemy sprites. What I want to do is accessing them and change their velocity values so they can move backwards and forwards. My code is below. This is from my create(). //Create an empty enemy group we can user as a container. enemies = game.add.group(); //Enable physics on the enemies group enemies.enableBody = true; My code for the enemy is below. function enemyMovement(game, player, platforms, speed, enemies) { // Collide the player and the stars with the platforms game.physics.arcade.collide(player, enemies); game.physics.arcade.collide(enemies, platforms); // Reset the enemies velocity (movement) enemies.body.velocity.x = 150; }; Also I raised a post earlier about key events but I didn't get any responces. The question for that is below. Any ideas?
  7. Hi Guys, I'm pretty new to Phaser Game development. I'm trying to make a cool 2D platformer. I've created a very basic first level, enough to let me start working on the player controls. One thing I want to do is add a double jump feature to my player. I'm trying to find something like a key.up function to use to stop it so my player doesn't just hold down the spacebar to jump really high. Here is my code behind jumps below. if (userKeys[2].onDown && player.jumpCount < 2) { player.body.velocity.y = -350*upForce; player.jumpCount++; console.log(player.jumpCount); } I think what I need is the processKeyUp function, in the keyboard.js. I'm not sure how I call it. Any ideas? Also right now I am using Cloud9 as my development environment. I've heard good things about mighty editor. Which one do you guys prefer?