• Content count

  • Joined

  • Last visited

About onlycape

  • Rank
    Advanced Member

Recent Profile Visitors

439 profile views
  1. onlycape

    AudioContext Error

    Hi @MackeyK24 , The latest Chrome update causes this problem. Now you need the first sound to be caused by the user (click, touch ...), only then you can play sounds without user intervention. In my case, I added a sound (with 0 volume) on the play button. And here other solution: Regards.
  2. onlycape

    how to call a function as argument ?

    Hi @espace, There is a scope problem. You don't need to put the argument inside an anonymous function. The argument is already a function. This code works: var wait = function(callback,duration){ setTimeout(callback, duration); }; var f = function(){ console.log('executed'); }; wait(f,500); Regards.
  3. onlycape

    Why use "this " keyword in Phaser states

    In this link they explain in detail the use of the "this" keyword in javascript: In my humble opinion (I'm a newbie in javascript and Phaser), your question is more related to javascript than to Phaser framework. Using more time in javascript learning at the end will save you a lot of time when developing in Phaser, and will provide you with other resources that in some cases the framework will not be able to offer. Regards.
  4. onlycape

    Chrome Update Takes ALL Sound From Html5 Games

    Phaser CE has already solved that problem in version 2.10.5. For other frameworks I dont know.
  5. Hi @EpicKingdom_ I had a similar problem with the mobile devices and the problem was the configuration of my viewport metatag.
  6. onlycape

    problem with

    Hi @Dzambor, The problem is that the callbacks did not send the game parameter to the nextWord (game) and nextLine(game) functions, and therefore could not create the time events since game was undefined. To fix it, I changed the callbacks of the time events. This is the code: var Game={}; Game.Intro = function(game) {}; var content = [ "The sky above the port was the color of television, tuned to a dead channel.", "From Neuromancer by William Gibson" ]; var line = []; var wordIndex = 0; var lineIndex = 0; var wordDelay = 120; var lineDelay = 400; Game.Intro.prototype = { create: function(game) { var t=this; console.log(game); text = game.add.text(32, 32, '', { font: "15px Arial", fill: "#19de65" }); nextLine(game); } } function nextLine(game) { if (lineIndex === content.length) { /* // We're finished this.state.start('MainMenu');*/ console.log('Code for new state disabled'); } // Split the current line on spaces, so one word per array element line = content[lineIndex].split(' '); var g=game; // Reset the word index to zero (the first word in the line) wordIndex = 0; // Call the 'nextWord' function once for each word in the line (line.length), line.length, function(){nextWord(game);}, this); // Advance to the next line lineIndex++; } function nextWord(game) { // Add the next word onto the text string, followed by a space text.text = text.text.concat(line[wordIndex] + " "); // Advance the word index to the next word in the line wordIndex++; // Last word? if (wordIndex === line.length) { // Add a carriage return text.text = text.text.concat("\n"); // Get the next line after the lineDelay amount of ms has elapsed, function(){nextLine(game);}, this); } } Regards.
  7. onlycape

    multiple states start

    Hi @zidein, For this case maybe Phaser 3 adapts better to what you want, since it is designed to run several states at same time if necessary.\scenes\multiple scenes from classes.js Regards.
  8. onlycape

    Spawning sprites randomly for endless runner

    @laduree77 Don't worry , the problem remains the same. Knowing the upper left corner (-100 , 0) and the lower right corner (1700 , 310) of the rectangle of the world bounds and the width and height of the obstacles (70x70), the possible coordinates of these will be: -100 < obstacle.x < 1630 0 < obstacle.y < 240 In the code some obstacles are generated outside these limits.
  9. onlycape

    Game Object not being removed after code is deleted

    Hi @TheScruffyGuy, It seems a problem with the browser cache. Have you refreshed the browser after save the new code ?. Greetings.
  10. onlycape

    Spawning sprites randomly for endless runner

    @laduree77 Upsss, I think it's my fault . The problem is that the initial "Y" coordinate of some obstacles is outside the world bounds and I imagine that it can produce that behavior. In this expression: ((Math.random() * 250) - 20) change "-20" with any positive value. Tell me if that solves the problem. PS: You should post a new thread for a new problem, because that way you'll find help more easily and help other people with the same problem.
  11. onlycape

    Spawning sprites randomly for endless runner

    @laduree77 In your jump condition you have to change: this.player.body.touching.down with this.player.body.onFloor()
  12. onlycape

    Spawning sprites randomly for endless runner

    Hi @laduree77, I have tested the code I showed you before and it works for me (Phaser 2.10.1). Here is the problem in your new code: = this.height - 50; "this.height" is undefined. You have to use "" or "game.height". After that, you don't need apply physics to the ground. Right now, the call to makeObstacles in the update method isn't doing anything because it needs a parameter (number of obstacles to generate). But if you generate obstacles in the update () (it is executed 30/60 times per second), you must implement a method to destroy the obstacles that you don't need or in a few seconds you will have thousands, with which you will have performance problems and the game will be unplayable. The main idea of the code that I showed you is the reuse of the obstacles (I created 4, but obviously you can put the ones you want) to avoid to collapse the resources and the creation of new objects (slower than reusing existing ones). Greetings.
  13. onlycape

    Spawning sprites randomly for endless runner

    Hi @laduree77 , Some points that I think can help you to optimize your code: 1) In your current code you are continuously creating elements of the "obstacle" group, which causes a significant drop in the fps. The best option in your case is to recycle the obstacles when they leave the screen. 2) For collisions with the ground you can redefine the world bounds and use bottom bound as a floor. 3) When you load an asset of the game, it does not disappear when changing to another state. Here you only need the first preload(). 4) The creation of objects or variables that are not going to change is better done in the create () method, since it only runs one time. This is the case of "cursors". Here a possible solution to your problem of collisions with the ground and the fall of the fps: var game = new Phaser.Game(820, 360, Phaser.AUTO); var mainMenu = function(game) {}; mainMenu.prototype = { preload: function() { //preloading assets this.load.atlas('sprites', 'assets/img/spritesheet.png', 'assets/img/sprites.json'); }, create: function () { // background this.background =, -30,, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.background =, 310,, 60, 'sprites', 'ground'); this.background.autoScroll(-200, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny0000'); this.player.animations.add('run', Phaser.Animation.generateFrameNames('bunny', 4, 5, "", 4), 10, true);'run', 10, true); // logo this.splash = this.add.sprite(, - 40, 'sprites', 'logo'); this.splash.anchor.setTo(0.5); }, update: function () { if ( {'gamePlay'); } } }; var obstacle; var gamePlay = function(game) {}; gamePlay.prototype = { create: function () { //world bounds rectangle ******************************************************** = -100; = game.width + 100 + (1700-820); = game.height-50; // physics engine game.physics.startSystem(Phaser.Physics.ARCADE); // background this.background =, -30,, 390, 'sprites', 'background'); this.background.autoScroll(-100, 0); // ground this.ground =, 310,, 60, 'sprites', 'ground'); this.ground.autoScroll(-300, 0); // player this.player = this.add.sprite(30, 253, 'sprites', 'bunny0000'); this.player.animations.add('right', Phaser.Animation.generateFrameNames('bunny', 4, 5, '', 4), 10, true);'right', 10, true); // physics on sprites game.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; //give player slight bounce this.player.body.bounce.y = 0.2; this.player.body.gravity.y = 1000; this.player.body.collideWorldBounds = true; //create group for obstacles obstacle =; obstacle.enableBody = true; obstacle.physicsBodyType=Phaser.Physics.ARCADE; //spawn obstacles this.makeObstacles(4); }, makeObstacles: function (numberOfHills) { for (var i = 0; i < numberOfHills; i++) { var hill = obstacle.create(((Math.random() * 900) + 800), ((Math.random() * 250) -20), 'sprites', 'obstacle'); //hill.body.immovable = true; //hill.scale.x *= -1; hill.body.gravity.y = 200; hill.body.velocity.x = ((Math.random() * -200) - 100); hill.body.collideWorldBounds = true; } }, update: function () { //look for hills out of screen to recycle obstacle.forEach(function(item){ if(item.x < -60){ item.reset(((Math.random() * 900) + 750), ((Math.random() * 250) - 20)); item.body.gravity.y = 200; item.body.velocity.x = ((Math.random() * -200) - 100); item.body.collideWorldBounds = true; } }) //add arrow keys for movement var cursors = this.input.keyboard.createCursorKeys(); //reset player velocity this.player.body.velocity.x = 0; //moving player if (cursors.up.isDown && this.player.body.onFloor()) { this.player.body.velocity.y = -850; } else if (cursors.right.isDown) { this.player.body.velocity.x = 60;'right'); } else if (cursors.left.isDown) { this.player.body.velocity.x = -90;'right'); } } }; var gameOver = function(game) {}; gameOver.prototype = { create: function () { console.log('create'); game.stage.backgroundColor = '#4488AA'; //click to start text - 100, + 80, 'Click to return to main menu', { font: "30px Raleway"} ); }, update: function () { if ( {'mainMenu'); } } } game.state.add('mainMenu', mainMenu); game.state.add('gamePlay', gamePlay); game.state.add('gameOver', gameOver); game.state.start('mainMenu'); Greetings and good luck!!
  14. onlycape

    [Solved]How to loop ??

    Hi @fatboyarming , This is a possible solution to your problem (code tested here: var stepOne = true; function create() {*10,function(){ //Step 1 * 5, function(){ stepOne = false; stepTwo = true; stepThree = false; console.log('go to step 2'); },this); //Step 2 * 8, function(){ stepOne = false; stepTwo = false; stepThree = true; console.log('go to step 3 '); },this); //Step 3 * 10, function(){ stepOne = true; stepTwo = false; stepThree = false; console.log('back to step 1 '); }, this); }, this); } Greetings.
  15. Hi @Mickety, I see some advantages using html5 for UI. If the game needs to be adapted to different sizes, using a html-based UI avoids easily problems with pixelated buttons and texts. It also allows you to use the entire available screen and not just the canvas. You can group the buttons and information in different div, and depending on the state of the game, hide or show the div/s for that state. A problem in the case of using this option is to position the elements on the canvas when it's smaller than the available screen, which using phaser would be very easy. Greetings.