Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

collision detection: custom class and array

Explorer ,
Mar 14, 2015 Mar 14, 2015

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.

TOPICS
ActionScript
436
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 15, 2015 Mar 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.

Translate
LEGEND ,
Mar 14, 2015 Mar 14, 2015

What other code do you have for that class?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2015 Mar 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,


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 15, 2015 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 15, 2015 Mar 15, 2015
LATEST

oh my god, it took 9 days but now I understand why the code wasn't working.

What calls the function where the collision gets detected?

All this time I didn't have

checkCollisionWithShip();

inside my mainLoop();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines