crffty

Members
  • Content count

    19
  • Joined

  • Last visited

About crffty

  • Rank
    Member

Contact Methods

  • Twitter
    crffty
  1. on tap

    I have a sprite jumping if the spacebar is pushed but i also want the same to happen on a mobile if the screen is tapped this.game.input.keyboard.addKeyCapture([Phaser.Keyboard.SPACEBAR]); cursors = this.input.keyboard.createCursorKeys(); this.jumpButton = this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) || this.input.onTap.add(onTap, this); what am i missing?
  2. text field

    Hi I'm trying to put a small text field that the player can type text into and them submit the the text. I've seen so may complicated ( over my head ) ways to do this but I was hoping for a simple solution. Just need to click on a box and be able to type in it, then cluck "subScore". this.subScore = game.add.sprite(this.game.world.centerX + 150, this.game.world.centerY + 100, 'subScore'); this.subScore.anchor.setTo(0.5, 0.5); // Enable input on the subScore button this.subScore.inputEnabled = true; // Attach a function to the input down ( click/tap) this.subScore.events.onInputDown.add(function() { var name = ""; var score = ""; $.ajax ( { url:"/vaultage/publicHTML/score.php", data:{name:name, score:score}, type:"post", success:function(result){ if (result === "success"){ alert ('yes'); } else { alert ('no'); }; } }); }, this); full repo: https://github.com/craftycal/vaultage thank you in advance for you help.
  3. velocity to 0

    thank you for your help. I have the obstacles, ground, background and player stopped but new obstacles are still being generated and moving across the screen. I also need to stop the timer without loosing to current count. and was thinking about how to get that number into a database update : function() { // time tracker var thisTime = new Date(); var diff = (thisTime.getTime() - this.startingTime.getTime())/1000; this.score.text = diff; }, endGame: function() { this.endGame = true; // stop everything this.obstacles.setAll('body.velocity.x', 0); this.ground.autoScroll(0, 0); this.background.autoScroll(0, 0); this.player.animations.stop(null, true); // timer stop // stop new obstacles from being created ??? <<<<<<<<< // game over text this.game.add.text(this.game.world.centerX - 150, this.game.world.centerY - 100, "game over", { font: "60px Raleway"} ); // place the buttons this.rePlay = game.add.sprite(this.game.world.centerX - 150, this.game.world.centerY + 100, 'rePlay'); this.rePlay.anchor.setTo(0.5, 0.5); this.subScore = game.add.sprite(this.game.world.centerX + 150, this.game.world.centerY + 100, 'subScore'); this.subScore.anchor.setTo(0.5, 0.5); // Enable input on the replay button this.rePlay.inputEnabled = true; // Attach a function to the input down ( click/tap) this.rePlay.events.onInputDown.add(function() { this.game.state.start('game'); }, this); }
  4. simply click button to restart

    I've tried this but its still not doing anything. not even a error. endGame: function() { this.game.paused = true; this.game.add.text(this.game.world.centerX - 150, this.game.world.centerY - 100, "game over", { font: "60px Raleway"} ); // place the reset button this.rePlay = game.add.sprite(this.game.world.centerX - 150, this.game.world.centerY + 100, 'rePlay'); this.rePlay.anchor.setTo(0.5, 0.5); // Enable input on the button... this.rePlay.inputEnabled = true; // Attach a function to the input down ( click/tap) this.rePlay.events.onInputDown.add(function() { this.game.state.start('game'); }, this); } i believe its to do with the game being paused ( pretty sure ) so how do i un-pause the game? this.game.paused = false; doesn't seem to do anything
  5. simply click button to restart

    hi. I'm having a bit of a brain dead moment!!! I need a super simple if button is clicked restart the game state in the pause menu. (Im using the game pause as a cheat end game screen) this is the function I'm working on - all I need is to be able to click 'rePlay'. endGame: function() { this.game.paused = true; this.game.add.text(this.game.world.centerX - 150, this.game.world.centerY - 100, "game over", { font: "60px Raleway"} ); // place the reset button this.rePlay = game.add.sprite(this.game.world.centerX - 150, this.game.world.centerY + 100, 'rePlay'); this.rePlay.anchor.setTo(0.5, 0.5); // if replay is pushed --- this if (this.rePlay.event) { game.state.start(game.state.current);; } }
  6. velocity to 0

    thanks for you reply. the idea is to have the game end on collision. so in order after the collision - player sprite to change to a "death" sprite, 2 seconds later - a game over/score screen with a play again button and a submit score button ( submit score will show a form - i'll me making a hight score table with a bit of php and SQL. ). the rest should be achievable but can the player sprite be changed whilst the game is pause? thanks for your advice.
  7. velocity to 0

    hello. I'm trying to stop my endless runner upon collision between the player and an 'obstacle' to do this i would like to stop the sprits form moving. velocity = 0. I can't work out how to do this though. thoughts? help? advice? beer? vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; // background this.background = this.game.add.tileSprite(0, 0, this.game.width, 360, 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground'); this.ground.autoScroll(-400, 0); // player this.player = this.add.sprite(45, 200, 'player'); this.player.animations.add('run'); this.player.animations.play('run', 15, true); // obstacles this.obstacles = this.game.add.group(); this.obstacles.enableBody = 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; // run the functions to create obstacles this.createObstacles(); this.nextObstacle(); }, update : function() { // look for collisions between sprites this.game.physics.arcade.collide(this.player, this.ground); if (this.game.physics.arcade.collide(this.player, this.obstacles)) { this.endGame(); }; // run the updateObstacle function for each obstacle this.obstacles.forEachAlive(this.updateObstacle, this); }, shutdown : function() { }, createObstacles: function() { // 1 x 5 keys == 5 obstacles this.obstacles.createMultiple(1, 'obstacle', [0, 1, 2, 3, 4]); this.obstacles.setAll('body.allowGravity', false); this.obstacles.setAll('body.immovable', true); }, nextObstacle: function() { // timer on next obstacle spawn this.resetNextObstacle(); this.time.events.add(this.rnd.between(750, 2000), this.nextObstacle, this); }, resetNextObstacle: function() { // reset each obstical to be re-used var obs = this.obstacles.getFirstDead(); // location of re-set dead obsticals if (obs) { obs.reset(); obs.left = this.world.bounds.right; obs.bottom = this.ground.top; obs.body.velocity.x = -400; } else { console.warn("None available", this.obstacles.children); } }, updateObstacle: function(obs) { // kill obstacle after it moves out of bounds if (obs.right < this.world.bounds.left) { obs.kill(); } }, endGame: function() { this.ground.autoScroll(0, 0); this.background.autoScroll(0, 0); this.obs.body.velocity.x = 0; } } thank you for your time and patients I'm still learning and its all a bit over my head sometimes. any advice would be greatly appreciated.
  8. event on collision - display scoreboard

    I'm still stuck on this problem. is anyone could help I would greatly appreciate it
  9. I've been following the Zenva "HTML5 Mobile Game Development with Phaser" tutorial but have run into a problem. I need to call the scoreboard on collegian between the player and obstacle sprites. but when I try I get "Uncaught TypeError: scoreboard is not a constructor". Can anyone suggest how this can be fix, or a better way of going about it. vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); // player this.player = this.add.sprite(45, 200, 'player'); // obstacles this.obstacles = this.game.add.group(); this.obstacles.enableBody = true; // score text this.score = this.game.add.bitmapText(700, 10, 'courier', this.game.time.totalElapsedSeconds(), 20); this.startingTime = new Date(); // run the functions to create obstacles this.createObstacles(); this.nextObstacle(); }, update : function() { // time tracker var thisTime = new Date(); var diff = (thisTime.getTime() - this.startingTime.getTime())/1000; this.score.text = diff; if (this.game.physics.arcade.collide(this.player, this.obstacles)) { this.endGame(); } }, shutdown : function() { }, endGame: function(player, obstacles) { player.kill(); this.obstacles.stopScroll(); this.ground.stopScroll(); this.background.stopScroll(); var scoreboard = new scoreboard(this.game); } } scoreboard prefab :- var scoreboard = function(game) { Phaser.Group.call(this, game); } scoreboard.prototype = Object.create(Phaser.Group.prototype); scoreboard.prototype.constructor = scoreboard; score.prototype.show = function(score) { var bmd, background, gameoverText, startText; bmd = this.game.add.bitmapData(this.game.width, this.game.height); bmd.ctx.fillStyle = '#000'; bmd.ctx.fillRect(0, 0, this.game.width, this.game.height); background = this.game.add.sprite(0,0, bmd); background.alpha = 0.5; this.add(background); this.y = this.game.height; }; scoreboard.prototype.restart = function() { gameoverText = this.game.add.bitmapText(0, 100, 'courier', 'game over', 20); gameoverText.x = this.game.width/2 - (gameoverText.textWidth /2); this.add(gameoverText); startText = this.game.add.bitmapText(0, 300, 'courier', 'Play Again', 16); startText.x = this.game.width/2 - (startText.textWidth /2); this.add(startText); this.game.add.tween(this).to({y: 0}, 1000, phaser.Easing. Bounce.out, true); this,game.input.onDown.addOnce(this.restart, this); }; scoreboard.prototype.restart = function() { this.game..state.start('Game', true, false); }; the scoreboard is basically the same as the zenva one with some small changes. i'll be altering more once I get my mead around what. but so far its not showing at all. *the prefab is linked in my index.html
  10. vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // score text this.score = this.game.add.bitmapText(700, 10, 'courier', this.game.time.totalElapsedSeconds(), 20); this.startingTime = new Date(); }, update : function() { var thisTime = new Date(); var diff = (thisTime.getTime() - this.startingTime.getTime())/1000*60; this.score.text = diff; }, shutdown : function() { } }
  11. I'm still not having any luck. I'm now using a bitmap font though... so thats good. I've tried so many variation but can't get a simple second counter to start at the beggining of the game state and to stop if the player collides with an 'obstacle'. so to start with I just need a second counter and then i'll work on stoping it on a collision. The bones of what I'm trying is below *edit. I have a separate preload vaultage.game = function() {}; this.time = 0; vaultage.game.prototype = { create : function() { // score text this.score = this.game.add.bitmapText(750, 10, 'courier', "0", 20); }, update : function() { // time every 1000ms time ++ // update the text this.score.setText(this.time); }, shutdown : function() { }
  12. I would like a timer to display in the top right of the game window. the time to be counting up in seconds . milliseconds to the 3rd decimal ( 00.000 ). i've found lots of examples to show an event on timer but not to just keep track of the game time and display. I'm assuming I need something in the update function to keep the time updating but not sure what. vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // timer this.timer = game.time.create(); this.game.add.text(20, 700, this.timer,{ font: "10px Raleway"} ); this.timer.start(); }, update : function() { }, shutdown : function() { }, }
  13. random obstacles

    DUDE!!!! you absolute legend, thank you!
  14. random obstacles

    I'm making an endless runner and need to generate an obstacle every 2-6 seconds for the player to jump over. I have three obstacle sprites, two along the 'ground' and one hanging from the top of the game window. I was thinking about using a group and randomly selecting a key from that group. sprites must enter from the right and move along y until they go of screen on the right then are killed and re-used again. I've been trying multiple methods to active this but with no luck, its all bit over my head, I'm not even sure whats going wrong. So i'm looking for a bit of direction and advice on how to active this. this is the code (mostly) without my attempts as it got a bit missy. vaultage.game = function() {}; // generate a obstacle at a random time between 2 seconds and 6 seconds this.obstacleRate = game.rnd.integerInRange(2000, 6000); this.obstacleTimer = 0; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; // sprites // background this.background = this.game.add.tileSprite(0, 0, this.game.width, 360, 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground'); this.ground.autoScroll(-180, 0); // player this.player = this.add.sprite(45, 200, 'player'); this.player.animations.add('run'); this.player.animations.play('run', 15, true); // obstacles this.obstacles = this.game.add.group(); // this.box = this.game.add.group(); // this.pole = this.game.add.group(); // this.cable = this.game.add.group(); // 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; // input cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); }, update : function() { this.game.physics.arcade.collide(this.player, this.ground); if (jumpButton.isDown && (this.player.body.touching.down)) { this.player.body.velocity.y = -400; } }, shutdown : function() { } createObstacles : function() { } }
  15. randomly generated obstacles for endless runner

    i've tried to just create one obstacle for now. but I'm getting a whole load of errors. game.js vaultage.game = function() {}; this.obstacleRate = game.rnd.integerInRange(2000, 6000); this.obstacleTimer = 0; vaultage.game.prototype = { create : function() { // obstacles this.obstacle = this.game.add.group(); }, update : function() { if (this.obstacleTimer < this.game.time.now) { this.createObstacle(); this.obstacleTimer = this.game.time.now + this.obstacleRate; } }, shutdown : function() { } createObstacle: function() { var x = this.game.width; var y = this.game.hight(290); var obstacle = this.obstacle.getFirstExists(false); if (!obstacle) { obstacle = new obstacle(this.game, 0, 0); this.obstacle.add(obstacle); } obstacle.reset(x, y); obstacle.revive(); } } } var obstacle = function(game, x, y, key, frame) { key = 'box'; phaser.Sprite.call(this, game, x, y, key, frame); this.anchor.setTo(0.5); // enable physics on the sprite without gravity this.game.physics.arcade.enableBody(this); this.body.allowGravity = false; // if the sprite is out of the game window remove the sprite this.checkWorldBounds = true; this.onOutOfBoundsKill = true; this.event.onKilled.add(this.onKilled, this); this.events.onRevived.add(this.onRevived, this); }; box.prototype = object.create(phaser.sprite.prototype); box.prototype.constructor = box; // when created box.prototype.onRevived = function () { // give the sprite some velocity this.body.velocity.x = -180; }; ^ obstacle.js prefab ^ 'box' is from preload.