Detecting Pixels

Started by
2 comments, last by diablo2_v 21 years, 2 months ago
Hey, Im designing a rts game with a few friends. Im using directdraw 7.0 to do this. I load all my graphics into sprites, and display them onto the screen. I plan on making the map/world just 1 large picture. Ill make a seperate 1 that is colour coded for different objects. eg. Water is gray, tree is red etc. What i dont know how to do is get the pixel colour of any given coordinate from the reference map picture from memory. I dont want to display it on the screen. FYI : Im using visual basic 6.0 Thanks [edited by - diablo2_v on February 9, 2003 8:21:24 PM]
'Programming is the only artform that fights back'
Advertisement
I tried something very similar to this a while ago in VB6. The way I got around it was to pre-load the collision map into a memory array. e.g.

Enum MapTile
0=Water
1=Lava
...
End Enum

Dim CArray(100,100) as MapTile

Picture1.picture=loadpicture("CollisionMap")

For g = 0 to 99
For H = 0 to 99
Carray(g,h) = picture1.point(g,h)
Next H
Next G

Works like a treat. You can speed it up a little by using the API GetPixel function. Also, the value returned by .Point is a double that contains the decimal values of R,G and B, so you''ll need to use something like Hex$ to get the seperate RGB values out.

Works perfectly though.

You can try to use direct memory interrogation on the collision map, but in VB this is dangerous and slow, so it''s much better to pre-cache it.

''Doing the impossible is kind of fun'' - Walt Disney
'Doing the impossible is kind of fun' - Walt Disney
Thanks, Ill give it a try. Hopefully it will work well.

I think thats going to be the next step in my game, whenever i get time to program
'Programming is the only artform that fights back'
I''ve run into another problem. If I preload the picture into a picture box, I need to get a certian pixel at an xcord and ycord of the screen.

In a picture box however, it doesn''t use the screen coordinates.

How can I get around this problem?
'Programming is the only artform that fights back'

This topic is closed to new replies.

Advertisement