getpixel() emulation & load anysize Bitmap demo

Post here your demos and examples with the source files.
Forum rules
Always post the games with a screenshot.
The file must have the ged and data files (complete game source)
Use the forum attachment to post the files.
It is always better to use the first post to put the game files

getpixel() emulation & load anysize Bitmap demo

Postby feral » 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 ...
getpixel.jpg
screengrab
click to enlarge


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)
getpixel.zip
ged and data files
(76.7 KiB) Downloaded 353 times

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.... :shock:

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 :D
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: getpixel() emulation & load anysize Bitmap demo

Postby feral » Fri Jul 25, 2008 2:19 am

loading bitmaps

This is very brief explanation of the load bitmap function included in this demo.

basically it opens the file in a binary way, rips out the 54 bit header AND gets the width and height of the bitmap (used in the for next loops to build the array)

It currently opens any size 24 bit bitmap upto 800 by 600 pixels, but it can do larger (you just need to make the storages arrays larger)

it does NOT use structs to open the fileheaders, because, I do not yet understand them myself :oops: , therefore should be easy enough for beginners to learn from.

It also works out the "padding" that uneven sized bitmaps use and discards it -

(bitmaps should be in multiples of four and if they are not, they are padded with rubbish data out to the nearest four)

you will also note: that it draws the bitmap upside down ( in the draw canvas). this is because bitmaps are stored upside down and need to be inverted..

later I will do a demo on how to write the bitmap back to a file, with padding if required..

feral

PS: I am hoping to learn targa (TGA) files soon so this getpixel emulation can also determine transparency values..
( which is what i need it for... :? )
User avatar
feral
 
Posts: 308
Joined: Sun Mar 16, 2008 6:27 am
Score: 47 Give a positive score

Re: getpixel() emulation & load anysize Bitmap demo

Postby Aidanator » Wed Nov 28, 2012 2:52 pm

I will be using this in a space game I am making. I figured why not get it to load an array then seed an entire galaxy from it. You will be in the credits list, anything more you want?
Aidanator
 
Posts: 1
Joined: Tue Sep 18, 2012 12:30 am
Score: 0 Give a positive score


Return to Game Demos

Who is online

Users browsing this forum: No registered users and 1 guest