Author Topic: Game Crashes when falling off bottom of screen.  (Read 1000 times)

edrobot

  • Member
  • **
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Okay, so I have a game that gives the following error when the player falls off the bottom of the screen;

[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

I'm pretty sure it's happening beacuse I'm calling FlxG.Collide(PlayerGroup, Map), but it doesn't happen when my player goes off the sides of the screen, only when he hits the bottom. What's wrong?

pixelomatic

  • Active Member
  • ***
  • Posts: 131
  • Karma: +0/-0
    • View Profile
Re: Game Crashes when falling off bottom of screen.
« Reply #1 on: Mon, May 7, 2012 »
Well it says pretty clear what the problem is. You have a null object reference. If you are sure it's happening in that function call, make sure you don't have any null objects in PlayerGroup or Map.

edrobot

  • Member
  • **
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Game Crashes when falling off bottom of screen.
« Reply #2 on: Tue, May 8, 2012 »
I checked, and I don't. Since it only happens when the player goes off the screen, I suspect it's an "out of bounds" error. Any way I can fix this?

hoolay

  • Member
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
    • ad-creatif
Re: Game Crashes when falling off bottom of screen.
« Reply #3 on: Sun, May 13, 2012 »
don't let him fall off the screen ...

Code: [Select]
if(player.y > level.height - player.height)
        player.y = level.height - player.height

but you must have an null object somewhere, try to find out adding a callback in your collide event
« Last Edit: Sun, May 13, 2012 by hoolay »