I’m using Adobe Flash CS4.
The language is Action Script 3
In my library I have 2 items:
- player
- wall
the player object is already functioning correctly with moving him around.
Now when I place multiple wall objects into the stage (wall = 32×32 px) I want to prevent the player from moving when he walks into a wall.
I’ve tried giving all the walls the same instance name and just check for a collision with that object but when I do that the collision only works for 1 of the walls.
I could give all the instances of wall a different collision script but this is way to time consuming, is there another way to globally define the wall as solid for the player?
Thanks in advance!
Your best bet would be to put all the wall instances in one parent movie clip and check the player instance for collision with it.
Or you can loop through all the wall instances and check separately. Might sound wasteful to you but that way you can add some optimizations to your collision detection routine. For example, why check for collision with the left wall if the player is in the right part of the screen.
Or you can use math to check for collisions and avoid Flash’s built-in routine whatsoever. Might sound like even more work but seeing how flawed it is (limited by frame-rate, etc.), I would go that way — if the game dynamics allows it, of course.