chaoskreator Posted August 4, 2016 Share Posted August 4, 2016 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 More sharing options...
drhayes Posted August 5, 2016 Share Posted August 5, 2016 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 More sharing options...
chaoskreator Posted August 5, 2016 Author Share Posted August 5, 2016 Thanks for the response. So would I need to create a sprite? Or could I get away with doing a graphic? Link to comment Share on other sites More sharing options...
drhayes Posted August 8, 2016 Share Posted August 8, 2016 Try a sprite. You can load the texture as a PNG or draw it dynamically via a bitmap data. Link to comment Share on other sites More sharing options...
Recommended Posts