For a space invaders clone, you'll be aware only one invader moves per frame. I'm having a problem whereby in my mainloop I check all invaders and remove those in collision from the alienObjectList
In addition, in order to move one invader per frame, I set a variable before my main loop:
Link:TLink = AlienObjectList.FirstLink()
Then inside the main loop I do this:
for each
alien.draw() ' draw all aliens
alien.collisionCheck() ' remove from AlienObjectList if collision
next
finally I use the Link variable to update the position of one invader per frame...
If Link <> Null
Local MyObject:TAlien1 = TAlien1(Link.Value()) 'cast object
MyObject.updatestate() ' update the onscreen position
Link = Link.NextLink()
Else
Link = AlienObjectList.FirstLink()
EndIf
I'm getting crashes during play because I think when doing checkCollision() and removing an alien from the list, its messing up the Link variable. Is there a better way ?
Error: Attempt to access field or method of Null Object
In addition, in order to move one invader per frame, I set a variable before my main loop:
Link:TLink = AlienObjectList.FirstLink()
Then inside the main loop I do this:
for each
alien.draw() ' draw all aliens
alien.collisionCheck() ' remove from AlienObjectList if collision
next
finally I use the Link variable to update the position of one invader per frame...
If Link <> Null
Local MyObject:TAlien1 = TAlien1(Link.Value()) 'cast object
MyObject.updatestate() ' update the onscreen position
Link = Link.NextLink()
Else
Link = AlienObjectList.FirstLink()
EndIf
I'm getting crashes during play because I think when doing checkCollision() and removing an alien from the list, its messing up the Link variable. Is there a better way ?
Error: Attempt to access field or method of Null Object