thisisandreww

Members
  • Content Count

    1
  • Joined

  • Last visited

About thisisandreww

  • Rank
    Newbie

Recent Profile Visitors

420 profile views
  1. I've started using Phaser for just about a week and I'm trying to develop something little. I apologize if the following code is messy. Basically I'm trying to get the array's element when I click on the sprite with p2 polygon collision. Could anyone please point me to how I can do that? Thanks. this.car = ["BMW", "Honda", "2","3","4"]; for(var i = 0; i < this.car.length; i++){ this.car[0] = game.add.sprite(100, 100+(i*100), 'car'); this.car[0].frame = 0; game.physics.p2.enable([this.car[i]],true); } click:function(pointer){ var x=game.camera.x +pointer.position.x; var y=game.camera.y +pointer.position.y; for(var i = 0; i < this.car.length; i++){ this.bodies = game.physics.p2.hitTest({x:x,y:y},[this.car[i]]); } if (this.bodies.length === 0) { this.result = "You didn't click a body"; } else { this.result = "You clicked: "; for (var i = 0; i < this.bodies.length; i++) this.result = this.result + // What should I write here to show that I've clicked on '2' / 'BMW' etc. ?? if (i < this.bodies.length - 1) { this.result = this.result + ', '; } } },