I am making a game for a gr.11 computer science class final project. It is similar to pokemon, and so object collision is an important part. The way i've set the game to recognize this is that any time the arrow key is pressed the function 'collision check is called'. this function goes through a list of sprites checking if they are incollision with your character. then returns the info as a bollean (called collision)
This has worked in every form i've used it in so far. (i open new forms as new areas in-game) HOWEVER in the newest area, it has given me the following error as soon as a key is pressed.
" System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="PokemonPURPLE" "
Any ideas how to solve this? any help would be appreciated.
Code:
Function CollisionCheck()
'set all NPCs and Walls to the array
Dim mysprite As Control = Hero 'dim hero as your sprite (wont work if global, dont ask me why)
allsprites(0) = box1
allsprites(1) = box2
allsprites(2) = box3
allsprites(3) = box4
allsprites(4) = Desk
allsprites(5) = Hero
allsprites(6) = kitchen
allsprites(7) = labshelf1
allsprites(8) = labshelf2
allsprites(9) = sciencething1
allsprites(10) = sciencething2
allsprites(11) = sciencething3
allsprites(12) = sciencething4
allsprites(13) = shelve
allsprites(14) = shelves
allsprites(15) = table
allsprites(16) = wall1
allsprites(17) = wall2
allsprites(18) = wall3
allsprites(19) = wall4
allsprites(20) = wall5
allsprites(21) = wall6
allsprites(22) = wall7
allsprites(23) = wall8
'evaluate the movement and check if their is a collision occuring, then return that result
For Each s As Control In allsprites
If s IsNot mysprite AndAlso s.Bounds.IntersectsWith(Hero.Bounds) Then
collision = True
Exit For
Else
collision = False
End If
Next
Return collision
End Function
" System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="PokemonPURPLE" "
Any ideas how to solve this? any help would be appreciated.