|
I need a bitmap reference in my sprite structure |
xmltorrent
Member #7,673
August 2006
|
How would I go about adding a reference to a bitmap in my sprite data structure? See I need it so I can finish my pixel-perfect collision detection routine for a bullet-to-obstacle. I need the bitmap reference so I can access the bitmap itself to get the pixels. Here is my sprite structure: typedef struct SPRITE{ My first thought was to add standard statement of the BITMAP type like: BITMAP *reference; I tried that but when I went to access it like this: obstacle->reference; The compiler gave me an error. Unless I'm trying to access it the wrong way... Any help would be appreciated. Thanks in advance. |
Tomasz Grajewski
Member #4,284
February 2004
|
Is this what You meant? And what was the error returned from the compiler? ___________________________________________________________________________________________ |
LennyLen
Member #5,313
December 2004
|
Use: obstacle.reference, not obstacle->reference. edit: Tomasz, neither of the methods you describe work.
|
xmltorrent
Member #7,673
August 2006
|
Sorta but not the ticket. Like for testing purposes, I need the structure to hold the bitmap that represents the sprite. Then I want to draw the bitmap to the back buffer to make sure that the reference is holding the bitmap. I did what you had there in the code and it compiled but when I went to run the program, it crashed at run-time. EDIT: I added this to my sprite structure: BITMAP *reference; Then just set it equal to the bitmap in the animation array: player->reference = player_images[0]; Then drew it to the buffer: draw_sprite(buffer, player->reference, 300, 400); |
LennyLen
Member #5,313
December 2004
|
The following compiles and executes for me flawlessly:
|
Rick
Member #3,572
June 2003
|
You probably didn't load it correctly. Most likely your bitmap is NULL, so when you try to use it it gives an error. ======================================================== |
|