Topic: Game Programming /
Transitioning to blitting: MouseEvents and Collision detection issues
Hello,
I have started to learn how blit in an effort to make the type of games I want, mainly ones with a lot of projectiles/units.
I have been using this 3 part video tutorial:
http://gotoandlearn.com/play.php?id=140
I can blit now IE: render my bitmaps to the screen using a single bitmap and copyPixels(). But I have run into a few issues of things that I take for granted when using displayObject:
MouseEvents
Collision
I have created a simple tile map for a rudimentary TD (To learn concepts only, no one needs me to release another generic TD) using 2 tiles I have created one that will be a path and is used for units to travel on and the other will be non pathable ground that will be buildable; pretty standard stuff. So the first issue is simple, I want to click on a buildable tile to create a tower. The problem is, bitmaps can’t handle mouseEvents. FRom what I have read this leaves me with 2 possible solutions. Solution:
1) Wrap my bitmap objects in sprites – This solution seems to defeat the entire purpose of blitting. If I am going to wrap my bitmap in a sprite I might as well just use a sprit in the first place as I will have all the overhead I was looking to avoid.
2) Math – Attach an event listener to the main class (extends sprite) and use math to determine which tile I am clicking on. I am unsure of how to do this. The thought I have on doing this right now is that I pass the coordinates of the mouseclick to an event that checks the the coords against an array ot tiles. My tiles have x and y properties and width and height so I should be able to determine which tile I am clicking on. This could also get pretty intensive on maps with a lot of tiles. Any thoughts on this would be great.
The next issue is collision detection. I have no idea how to go about this with bitmapData. I am just getting past using hittest (A sin, I know) and am not sure how to go about implementing a simple system. Am I supposed to check actual pixels for overlap or am I supposed to define a geometric shape in my classes that I use to test for overlap based on the position of the bitmapdata render?
|