Okay so im happily plodding along in my coding and as some have may followed im using my Nifty Sprite class:
http://www.zianet.com/codejoy/NSprite.cpp
http://www.zianet.com/codejoy/NSprite.h
and it seems to be working great, I have my main character running around on the screen and grabbing pieces.
The pieces he grabs is defined in my main application header file as:
...
NSprite m_pieces[4];
NSprite m_playerpieces[4];
since there are 4 different types of pieces (red, blue, green, purple);
I then in my init code using the above methods from the sprite class I proceed to create the sprite, and set the proper frame (single frame) of animation:
the lovely really lovely thing is in my process next frame when I try to draw the sprite, it dont work ON JUST ONE PIECE... the m_piece[RED] where RED, BLUE, GREEN, P URPLE are enumerated as:
enum pieces[RED=0, BLUE, GREEN, PURPLE];
It works fine for m_piece[BLUE] and the rest, and it works great for m_playerPiece[RED] all the way up purple too.
I tracked the error to Draw_Sprite and apparently when I try to call m_piece[0].Draw_Sprite(&backbuffer); the rects for just that sprite [0] is invalid as i get the GDERR_INVALIDRECTS. So I am curious as to why those rects for that one element of the array is wrong, as one can see, i do the same calls for m_piece[BLUE] m_piece[GREEN] and m_piece[PURPLE]. I even went so far as to nudge the array up:
NSprite m_piece[5]; and then make a SRED=4 and say:
m_piece[SRED].Create_Sprite(...)
m_piece[SRED].Load_Frame_Sprite(...)
...
...
m_piece[SRED].Draw_Sprite(&backbuffer);
It works great, but for some reason the m_piece[0]...just isnt working and I cannot figure out why.
Any ideas? im really lost as to why its not working, am I instantiating the classes wrong? do I need a new operator somewhere? its odd to me since the m_playerpieces[4] stuff works fine, and even the rest of m_piece[>1] calls work fine...just that one element doesn't and I haven't a clue why.
Internally I know some of the values are getting fudged which leads me to believe that yes somewhere memory isnt going how i think it should (again do I need a new operator? like:
NSprite m_piece[4]=new NSprite[4]; ?
hmm perhaps im getting confused with java again)
Ugh this is defiantly a show stopper, I mean i could just do as i said erlier, load the red piece in element 4 instead of 0 and change the rest of the game code to acceess that ignoring m_piece[0] all the time, but I shouldn't have to do that since m_piece[0] should be working.
Well if this made sense or even sparked a idea for a tree or two for me to bark up, id be glad as to me this error is very devious.
-Shane
http://www.zianet.com/codejoy/NSprite.cpp
http://www.zianet.com/codejoy/NSprite.h
and it seems to be working great, I have my main character running around on the screen and grabbing pieces.
The pieces he grabs is defined in my main application header file as:
...
NSprite m_pieces[4];
NSprite m_playerpieces[4];
since there are 4 different types of pieces (red, blue, green, purple);
I then in my init code using the above methods from the sprite class I proceed to create the sprite, and set the proper frame (single frame) of animation:
- Code:
m_piece[RED].SetTransColor(0,0,0);
m_piece[RED].Create_Sprite(0, 0, 16, 16, 1, SPRITE_ATTR_SINGLE_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_CHIPS, NULL);
m_piece[RED].Load_Frame_Sprite(0, 0, 0, BITMAP_EXTRACT_MODE_CELL);
m_piece[BLUE].SetTransColor(0,0,0);
m_piece[BLUE].Create_Sprite(0, 0, 16, 16, 1, SPRITE_ATTR_SINGLE_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_CHIPS, NULL);
m_piece[BLUE].Load_Frame_Sprite(0, 1, 0, BITMAP_EXTRACT_MODE_CELL);
m_piece[GREEN].SetTransColor(0,0,0);
m_piece[GREEN].Create_Sprite(0, 0, 16, 16, 1, SPRITE_ATTR_SINGLE_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_CHIPS, NULL);
m_piece[GREEN].Load_Frame_Sprite(0, 2, 0, BITMAP_EXTRACT_MODE_CELL);
m_piece[PURPLE].SetTransColor(0,0,0);
m_piece[PURPLE].Create_Sprite(0, 0, 16, 16, 1, SPRITE_ATTR_SINGLE_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_CHIPS, NULL);
m_piece[PURPLE].Load_Frame_Sprite(0, 3, 0, BITMAP_EXTRACT_MODE_CELL);
m_piece[SRED].SetTransColor(0,0,0);
m_piece[SRED].Create_Sprite(0, 0, 16, 16, 1, SPRITE_ATTR_SINGLE_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_CHIPS, NULL);
m_piece[SRED].Load_Frame_Sprite(0, 0, 0, BITMAP_EXTRACT_MODE_CELL);
//frame: 0 1 2 3
// left right down up
m_playerPiece[RED].SetTransColor(0,0,0);
m_playerPiece[RED].Create_Sprite(8*16, 8*16, 16, 16, 4, SPRITE_ATTR_MULTI_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_PLAYERPIECES, NULL);
m_playerPiece[RED].Load_Frame_Sprite(0, 0, 0, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[RED].Load_Frame_Sprite(1, 1, 0, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[RED].Load_Frame_Sprite(2, 2, 0, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[RED].Load_Frame_Sprite(3, 3, 0, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[BLUE].SetTransColor(0,0,0);
m_playerPiece[BLUE].Create_Sprite(8*16, 8*16, 16, 16, 4, SPRITE_ATTR_MULTI_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_PLAYERPIECES, NULL);
m_playerPiece[BLUE].Load_Frame_Sprite(0, 0, 1, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[BLUE].Load_Frame_Sprite(1, 1, 1, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[BLUE].Load_Frame_Sprite(2, 2, 1, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[BLUE].Load_Frame_Sprite(3, 3, 1, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[GREEN].SetTransColor(0,0,0);
m_playerPiece[GREEN].Create_Sprite(8*16, 8*16, 16, 16, 4, SPRITE_ATTR_MULTI_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_PLAYERPIECES, NULL);
m_playerPiece[GREEN].Load_Frame_Sprite(0, 0, 2, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[GREEN].Load_Frame_Sprite(1, 1, 2, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[GREEN].Load_Frame_Sprite(2, 2, 2, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[GREEN].Load_Frame_Sprite(3, 3, 2, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[PURPLE].SetTransColor(0,0,0);
m_playerPiece[PURPLE].Create_Sprite(8*16, 8*16, 16, 16, 4, SPRITE_ATTR_MULTI_FRAME | SPRITE_ATTR_VISIBLE, GDSURFACE_SYSTEMMEMORY, 0, 16, hInstance, IDB_PLAYERPIECES, NULL);
m_playerPiece[PURPLE].Load_Frame_Sprite(0, 0, 3, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[PURPLE].Load_Frame_Sprite(1, 1, 3, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[PURPLE].Load_Frame_Sprite(2, 2, 3, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[PURPLE].Load_Frame_Sprite(3, 3, 3, BITMAP_EXTRACT_MODE_CELL);
m_playerPiece[current_piece].SetCurrFrame(player_Dir);
m_playerPiece[current_piece].Set_Pos_Sprite(currentPlayer_X *16, currentPlayer_Y*16);
the lovely really lovely thing is in my process next frame when I try to draw the sprite, it dont work ON JUST ONE PIECE... the m_piece[RED] where RED, BLUE, GREEN, P URPLE are enumerated as:
enum pieces[RED=0, BLUE, GREEN, PURPLE];
It works fine for m_piece[BLUE] and the rest, and it works great for m_playerPiece[RED] all the way up purple too.
I tracked the error to Draw_Sprite and apparently when I try to call m_piece[0].Draw_Sprite(&backbuffer); the rects for just that sprite [0] is invalid as i get the GDERR_INVALIDRECTS. So I am curious as to why those rects for that one element of the array is wrong, as one can see, i do the same calls for m_piece[BLUE] m_piece[GREEN] and m_piece[PURPLE]. I even went so far as to nudge the array up:
NSprite m_piece[5]; and then make a SRED=4 and say:
m_piece[SRED].Create_Sprite(...)
m_piece[SRED].Load_Frame_Sprite(...)
...
...
m_piece[SRED].Draw_Sprite(&backbuffer);
It works great, but for some reason the m_piece[0]...just isnt working and I cannot figure out why.
Any ideas? im really lost as to why its not working, am I instantiating the classes wrong? do I need a new operator somewhere? its odd to me since the m_playerpieces[4] stuff works fine, and even the rest of m_piece[>1] calls work fine...just that one element doesn't and I haven't a clue why.
Internally I know some of the values are getting fudged which leads me to believe that yes somewhere memory isnt going how i think it should (again do I need a new operator? like:
NSprite m_piece[4]=new NSprite[4]; ?
hmm perhaps im getting confused with java again)
Ugh this is defiantly a show stopper, I mean i could just do as i said erlier, load the red piece in element 4 instead of 0 and change the rest of the game code to acceess that ignoring m_piece[0] all the time, but I shouldn't have to do that since m_piece[0] should be working.
Well if this made sense or even sparked a idea for a tree or two for me to bark up, id be glad as to me this error is very devious.
-Shane