Sign in to follow this  
noahduv

Click event on sprite

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/phaser-ce@2.9.1/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>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.