getpixel() emulation & load anysize Bitmap demo
Posted: Fri Jul 25, 2008 1:58 am
as most of you know there is currently no getpixel() function in GE. there have been quite a few requests for it tho,
the next post will explain the loadbitmap section
so, for those of you who want a getpixel() function for game "hotspots", or some other getpixel() gaming uses ...
This is one way to emulate it. it doesn't do everything you may want, but works very well on map type games
(I tried to make this because i needed it for another project, but, it doesn't work for what I needed it to do . .. so i hope it may help someone else, as it does work well for other things)
how it works..
1. a "background/map" screen is loaded into a pixel array..
This means your backdrop or map must be a 24 bit bitmap and be stored in the same directory as your executable ( sorry i currently only know how to do bitmaps)
2. the program then needs to open the bitmap and extract all the pixel data and convert it to an array ( which is what this program does)
3. the mouse coordinates are then matched to the pixel array data (not the picture, but to the array we built) and the results are displayed ( or can be used)
NOTE1: This demo actually then uses the "pixel array data" that has been loaded, to "draw" the bitmap onto a canvas...
I left this in there as some may want to know how to do this.. but, because we already have the pixel data we don't actually need the picture....
AND, as It takes some time to draw the picture to the screen (drawing is slow)
However, as we have already loaded the pixel data into an array, we do NOT have to "draw" the map, instead we can load it as a normal animation and display it as a actor , ie: like an overlay....which means it will be loaded MUCH faster.
Simply delete the "map" canvas actor (and scripts) and create a new normal actor, and add the "map" as a animation.
All you need to do then, is make sure that the actors coordinates are lined up with the screen. eg top left corner must match top left corner of screen. so that the pixel data array matches the actual actors picture.
NOTE2: this is setup as a single screen game... it is possible to make scrolling maps/multiple screen games etc
not sure if I explained this well, so, if there are any questions please ask.
feral
the next post will explain the loadbitmap section
so, for those of you who want a getpixel() function for game "hotspots", or some other getpixel() gaming uses ...
This is one way to emulate it. it doesn't do everything you may want, but works very well on map type games
(I tried to make this because i needed it for another project, but, it doesn't work for what I needed it to do . .. so i hope it may help someone else, as it does work well for other things)
how it works..
1. a "background/map" screen is loaded into a pixel array..
This means your backdrop or map must be a 24 bit bitmap and be stored in the same directory as your executable ( sorry i currently only know how to do bitmaps)
2. the program then needs to open the bitmap and extract all the pixel data and convert it to an array ( which is what this program does)
3. the mouse coordinates are then matched to the pixel array data (not the picture, but to the array we built) and the results are displayed ( or can be used)
NOTE1: This demo actually then uses the "pixel array data" that has been loaded, to "draw" the bitmap onto a canvas...
I left this in there as some may want to know how to do this.. but, because we already have the pixel data we don't actually need the picture....
AND, as It takes some time to draw the picture to the screen (drawing is slow)
However, as we have already loaded the pixel data into an array, we do NOT have to "draw" the map, instead we can load it as a normal animation and display it as a actor , ie: like an overlay....which means it will be loaded MUCH faster.
Simply delete the "map" canvas actor (and scripts) and create a new normal actor, and add the "map" as a animation.
All you need to do then, is make sure that the actors coordinates are lined up with the screen. eg top left corner must match top left corner of screen. so that the pixel data array matches the actual actors picture.
NOTE2: this is setup as a single screen game... it is possible to make scrolling maps/multiple screen games etc
not sure if I explained this well, so, if there are any questions please ask.
feral