• Content count

  • Joined

  • Last visited

  1. Getters and Setters?

    Hero.prototype.move = function (direction) { const SPEED = 200; this.body.velocity.x = direction * SPEED; }; So I need to change SPEED to another value during gameplay - I thought I needed to use a setter, but I'm unsure how to implement it? (i realise i need to change it to var)
  2. Random level generation

    Been looking into this and have found chance.js and I was wondering how I could achieve random values when the JSON arrays are nested like this is: "coins": [ {"x": 147, "y": 525}, {"x": 189, "y": 525}, {"x": 399, "y": 399}, {"x": 357, "y": 420}, {"x": 336, "y": 462}, {"x": 819, "y": 525}, {"x": 861, "y": 525}, {"x": 903, "y": 525} ],
  3. Random level generation

    Thanks for the reply - how would I achieve this (code wise) in Phaser?
  4. Random level generation

    { "platforms": [ {"image": "ground", "x": 0, "y": 546}, {"image": "grass:4x1", "x": 420, "y": 420} ], "decoration": [ {"frame": 2, "x": 630, "y": 504}, {"frame": 2, "x": 663, "y": 504}, {"frame": 2, "x": 697, "y": 504}, {"frame": 3, "x": 756, "y": 504}, {"frame": 1, "x": 84, "y": 504}, {"frame": 0, "x": 252, "y": 504}, {"frame": 4, "x": 462, "y": 378} ], "coins": [ {"x": 147, "y": 525}, {"x": 189, "y": 525}, {"x": 399, "y": 399}, {"x": 357, "y": 420}, {"x": 336, "y": 462}, {"x": 819, "y": 525}, {"x": 861, "y": 525}, {"x": 903, "y": 525} ], "hero": {"x": 21, "y": 525}, "spiders": [ ], "door": {"x": 231, "y": 546}, "key": {"x": 525, "y": 336} } I'm in the middle of making a platformer game. I am now trying to have some random level generation occurring, but I am unsure how to proceed. I use JSON files for the layout of the levels, but they are currently precoded. I know I will be using some form of a randomiser but I need certain things to stay the same. For instance, the "ground" and "grass" part need to remain the same as these point to the images used for the platform, but I need the digits inside to be randomly generated. Any tips on how to do this?
  5. How to unpause

    Is there any way of achieving this without having to upgrade from Kore Springs as it breaks when I do and obviously I'd rather not have to update all my code if possible?
  6. How to unpause

    It appears to be working on there. I wonder if I should attempt to upgrade my version of Phaser and hope it doesn't break!?
  7. How to unpause

    Chrome (most recent version) and mouse
  8. How to unpause

    So - I have two buttons - one for pausing the other for unpausing pauseButton = this.game.add.button(this.game.world.centerX, 500, 'restartButtonimg', pauseButtonAciononClick, this, 2, 1, 0); pauseButton.anchor.setTo(0.5, 0.5) unpauseButton = this.game.add.button(this.game.world.centerX, 300, 'restartButtonimg', unpauseButtonAciononClick, this, 2, 1, 0); When clicked, they call - function pauseButtonAciononClick () { this.game.paused = true; } function unpauseButtonAciononClick () { this.game.paused = false; } The pause button works fine in that the game is paused. However, the unpause does not work in that it doesn't unpause, but I coded it to do a console.log which it did do, so I am unsure what is wrong? It seems that the button for unpause does not respond, as I guess input is paused, but if you are saying that it shouldn't disrupt the update process then I'm unsure how to fix it? Using Kore Springs. Thanks
  9. How to unpause

    Hi - thanks for the reply. So far, being a complete amateur, I have only been using this.game.paused = true; which does achieve the pausing but without the ability to unpause - not sure if this is the best way or not. I am using the Kore Springs version as the tutorial I am following is based on that - would that be the issue?
  10. How to unpause

    Hi, I have set up the pausing function of my game, but it seems to be disabling all input when it is set to true. How do I fix this?
  11. OOP for this or not?

    So, I want to create a menu for displaying the controls to my game - I will be using multiple variables, inevitably, for each control explanation. This will likely take the form of at least 5-7 variables, so instead of writing a variable out multiple times to achieve this, would constructing a new object per "explanation" be more efficient as I will have to pass this.game.world.CenterX for each one, as well as its position and its font colour, so I didn't know if it would be more efficient using OOP or not? If it would be, how could I achieve this? The heading.anchor.set part will remain the same for all "explanations", hence why I am considering implementing a more efficient way of achieving this. If I have misunderstood/misconstrued the usefulness of OOP in this, then please just say as I am still learning Phaser and OOP so I am unsure as to whether what I want to do could be done more efficiently or not. Thanks. ControlMenuState = {}; x = 480; y = 300; ControlMenuState.create = function () { this.game.stage.backgroundColor = '#6d94b5'; var heading = this.game.add.text(this.game.world.centerX, 100, 'Controls...', {fill: 'white'}); heading.anchor.set(0.5, 0.5); }
  12. Retain score after state change

    Hi. Thank you so much - it makes sense now how and why it works. It turns out that to fix it, it was relatively easy in just having to alter the onHerovsCoin function to this.game, so apologies for the trivial oversight. Thanks again.
  13. Retain score after state change

    Hi again. Thank you so much for your help, but I'm afraid it still didn't work - the coins, when collected, did not increment the counter and when I did a console.log(), it returned undefined. I was wondering whether there was anymore to add to the code, or for an alternative fix? I really appreciate your time - thank you! J
  14. Retain score after state change

    Hi Thank you for your reply, but I'm afraid I am still a little confused. I am following this tutorial and have linked the scoring part for your reference https://mozdevs.github.io/html5-games-workshop/en/guides/platformer/scoreboard/ I am unsure how to implement the game.score? As an alternative, I set var score = 0 and the part that increments (this.coinFont.text = `x${this.coinPickupCount}`;) I altered to (this.coinFont.text = `x${score}`;) to no avail. I realise that, as the this.coinPickupCount is being reset in the init() part, I need to make it persistent; however, I am still unsure how to achieve this. Thank you for your further assistance.
  15. Retain score after state change

    Hi, When changing levels/states, I want the coins collected (essentially the score) to remain constant throughout. Currently, the state change causes the score to be reset, obviously because the state restarts. How do I make the coins collected a persistent variable without causing inefficiencies or making a bad programming habit i.e. global variables? Thanks.