Jump to content

enable click on multiple rectangles


Recommended Posts


I have a game I'm messing around with. I have a background with slots drawn in. I'm trying to create a rectangle object over each slot:


create: function(){
        var cityPlots = [0];
        Game.obj.add.sprite(0, 0, 'cityBg');

        $.each(City.plots, function(id, data){
                var plot = new Phaser.Rectangle(data.left, data.top, City.tileWidth, City.tileHeight);
                plot.inputEnabled = true;
                plot.events.onInputDown.add(City.plotClick, {plot: id});
                cityPlots[id] = plot;

but i get plot.events is not a function. How can I do this?

Link to comment
Share on other sites

Phaser.Rectangles are not display objects and thus can't be drawn on the screen. You want to make them sprites, most likely. That's part of why they don't have an "events" property.

Also, you don't need jQuery's "each" method. Arrays have a forEach method like this: "City.plots.forEach(function(id, data) {});"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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