Sprite drawing problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
HighBuddha
Posts: 11
Joined: Thu Jun 15, 2006 12:46 am

Sprite drawing problem

Post by HighBuddha »

I have a sprite class setup which holds all my sprite data: position, texture-sheet, all that jazz. And a method that draws the sprite. This is the method:

Code: Select all

void CSprite::drawSprite(video::IVideoDriver* driver, bool idl)
{
     static int current_frame = 0;
     core::rect<s32> spriteRect(0+32*current_frame, 0, 32*(current_frame+1), 32);
     video::ITexture* sprite = getSpriteSheet();

     if(idl == false)
     {
             if(nextFrame())
             {
                            driver->draw2DImage(sprite, core::position2d<s32>(s_x + 32, s_y + 32),
                                spriteRect, 0, video::SColor(255,255,255,255), true);

                            current_frame++;
             }
             else
             {
                  driver->draw2DImage(sprite, core::position2d<s32>(s_x + 32, s_y + 32),
                                spriteRect, 0, video::SColor(255,255,255,255), true);
             }
     }else
     {
          driver->draw2DImage(sprite, core::position2d<s32>(s_x + 32, s_y + 32),
                                core::rect<s32>(0,0,32,32), 0, video::SColor(255,255,255,255), true);
     }


     if(current_frame >= MAX_FRAMES)
     {
                      current_frame = 0;
     }
}

Code: Select all

int main()
{
    MyEventReceiver receiver;

    IrrlichtDevice *device = createDevice(EDT_OPENGL,
         core::dimension2d<s32>(windowx, windowy),32,false,false,false,&receiver);

    if (device == 0)
       return 1;

    video::IVideoDriver* driver = device->getVideoDriver();

    if(driver == NULL)
              return 1;

    env = device->getGUIEnvironment();

    if(!player->loadSprites(driver, device))
    {
      QUIT = true;
    }


    while(device->run()&&!QUIT)
    {
     if(device->isWindowActive())
     {
      driver->beginScene(true, false, video::SColor(0,0,0,0));
      env->drawAll();

      switch(index)
      {
                   case 87:
                        player->move_player(1);
                        player->draw(driver, false);
                        break;
                   case 83:
                        player->move_player(2);
                        player->draw(driver, false);
                        break;
                   case 65:
                        player->move_player(3);
                        player->draw(driver, false);
                        break;
                   case 68:
                        player->move_player(4);
                        player->draw(driver, false);
                        break;
                   default:
                           player->draw(driver, true);
                           break;
      };

     }
    }
	device->drop();
	return 0;
}

this method gets called inside my main method when a key is hit (it is initially set to 0 so default is used). Depending on the key, a different sprite object is used (up, down, left, right). The object calls a mothod in my player class called draw which simply picks the sprite to draw (i dont think this is the problem so i won't post the code, please tell me if that is necessary) then calls the actual draw method above. The method checks if the sprite should be animated or not depending on the idl variable. if its false then it is animated. Using a timer, a check is made to see if enough time has elapsed. If so then frame_count increments. frame_count is used to determine which frame should be drawn. This seems like a logical way to do this but nothing is drawn, so I would like some help if anyone can spare some time.

thanks is advance.

(I am using irrlicht 1.1 and codeblocks, the lib for the timer is libwinmm.a)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

try a driver->endScene() after the switch block... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Now, what ???
Was this the error, or not ???
Would be nice if you tell us (me) if it was... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply