Jump to content

enable click on multiple rectangles


chaoskreator
 Share

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){
            if(id){
                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

 Share

  • Recently Browsing   0 members

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