Jump to content

noahduv
 Share

Recommended Posts

Basically I am making a cookie clicker type game for fun. I am trying to make the counter increase each time the sprite is clicked on but for some reason the click event on the sprite is never fired if i click on the sprite. I can't figure out why the click event isn't firing does anyone know why? Or a better way of doing this?

 

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>Shook Clicker</title>
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/phaser.js"></script>
    </head>
    <body>

    <script type="text/javascript">
      var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });

      var clicker;
      var clicks = 0;
      var scoreText;


      function preload()
      {
        game.load.image('clicker', 'assets/cookie.png');
      }

      function create()
      {
      clicker = game.add.sprite(game.world.centerX, game.world.centerY, 'clicker');
      clicker.anchor.set(.5);
      clicker.scale.setTo(.1,.1);
      clicker.inputEnable = true;
      scoreText = game.add.text(16,16, 'Computers Built: 0', {fontSize:'32px', fill: '#555'});
      clicker.events.onInputDown.add(listener, this);
      }

      function listener()
      {
        clicks++;
        scoreText.text = 'Computers Built: ' + clicks;
      }

      function update()
      {

  
      }

  </script>
  </body>
</html>

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...