OSamo

Members
  • Content Count

    4
  • Joined

  • Last visited

About OSamo

  • Rank
    Newbie

Contact Methods

  • Twitter
    OSamo_OS
  1. OSamo

    Phaser Tutorial 2 with States

    Thanks for the resource! I am checking it right now. Any clue on the bug that I am having?
  2. OSamo

    Phaser Tutorial 2 with States

    So, I am trying to expand upon the "Making your first game" tutorial (https://github.com/photonstorm/phaser/tree/master/resources/tutorials/02%20Making%20your%20first%20game) by creating states instead of running the game directly on the script tag in the html file. I have tried doing so by following the template provided, but I cannot answer must of the questions I have only by looking at it. I am also currently facing a bug that I would love some help in solving. The bug that I mentioned is freezing the game every time the player touches a star. The error I get is this one: Uncaught TypeError: Cannot read property 'kill' of undefined Lvl1.js:155 Lvl1.js is the file where I have the state. Line 155 points to the collectStar function: collectStar: function(player, star){ // Removes the star from the screen this.star.kill(); // <--This is line 155 // Add and update the score this.score += 10; this.scoreText.text = 'Score: ' + this.score;}collectStar is called when there is an overlap between the player and any member of the stars group (I believe) this.physics.arcade.overlap(this.player, this.stars, this.collectStar, null, this);Here I create and add the items to the stars group: var star = this.stars.create(i * 70, 0, 'star');That is all I have for the bug, now for the questions: I realized that I have to use "this" a lot, but I am still unsure as of why and when I have to use it. Do I use it when I reference items declared inside the state? Or with items inside the function? Why don't I have to include the parameters? (player, star) when calling collectStar? This was also the case in the tutorial, and there were no bugs there. How do I load items (sprites and whatnot) in one state, so that I can use it in another state? For example, loading items in the preload state to use in the game state. Thank you! *Edit You can find the current version of it here http://sammyisra.comoj.com/phaserGuy/index.html
  3. OSamo

    State structure and functions

    spencerLT, I have been following the template, somewhat, but I do not remember seeing anything about functions other than the ones that are overloaded. AbdSab, Adding "this" solved that, and other issues. Do I have to use "this" every time I reference a variable or function inside the state it was declared? How can I reference items that were initialized outside the current state?
  4. OSamo

    State structure and functions

    (Warning, new Phaser user ahead) I´m making my first tests with States on Phaser, and I am now having a problem creating functions inside states that are not the predefined ones (create, update, etc). All in all, this is the code that is giving me trouble: this.physics.arcade.overlap(player, stars, collectStar, null, this);I define my collectStar function like this, before it is ever called: collectStar: function(){// Removes the star from the screen star.kill(); // Add and update the score score += 10; scoreText.text = 'Score: ' + score;},This is inside a state on a different Javascript file called Lvl1.js. The error I am receiving when running on Chrome is this: Uncaught ReferenceError: collectStar is not defined Lvl1.js:127Line 127 is where collectStar is called.