Skip to main content
ogeezus
Known Participant
March 14, 2015
Answered

collision detection: custom class and array

  • March 14, 2015
  • 1 reply
  • 506 views

so I'm making a top-down shooter for fun, but have been struggling as I'm new to programming,

I have

var player: Player = new Player();

var Enemies: Array = new Array();

now I've been looking all over the net, but this is what I've been trying to work with.

                                public function checkCollisionWithShip(): void {

                                                for (var e = Enemies.length - 1; e >= 0; e--) {

                                                                if (Enemies.hitTestObject(player)) {

                                                                                trace(Enemies);

                                                                                Lives -= 1;

                                                                                updateUI();

                                                                                trace("ship collision!");

                                                                }

                                                }

                                }

However, everytime my ship(player) touches an enemy, nothing ever happens.

looking forward to your replies,

thanks a lot for your time.

This topic has been closed for replies.
Correct answer Ned Murphy

Unfortunately the code you are deciding needs to be shown is not the code that needs to be shown.  What calls the function where the collision gets detected?  I don't see anything for that.

1 reply

Ned Murphy
Legend
March 14, 2015

What other code do you have for that class?

ogeezus
ogeezusAuthor
Known Participant
March 15, 2015

http://pastebin.com/uzgg3hiQ

I have pasted the code you want to see, as I understand you wouldnt want to go through 400 lines

thank you for your help sir,


Ned Murphy
Ned MurphyCorrect answer
Legend
March 15, 2015

Unfortunately the code you are deciding needs to be shown is not the code that needs to be shown.  What calls the function where the collision gets detected?  I don't see anything for that.