0
\$\begingroup\$

Im just starting out with irrlicht (and c++) for 2d development and I followed the 2d tutorial, so I am able to draw a 2d texture on the screen (With draw2DImage) this seems to work fine.

So I made a seperate class where I draw a ship and also change it's position in the Update function, but here I run into a problem. The ship is drawn twice when I change it's position.

void Ship::Draw(irr::video::IVideoDriver * driver, irr::video::ITexture* texture) {
driver->draw2DImage((texture), this->position);
}

void Ship::Update(float gameTime) {
this->position.set(this->position.X += 1, this->position.X += 1);
}

The ship is drawn once on its original place (I guess 0,0) but it seems asif the ship is being copied and then that copy is.

in my main.cpp I have this:

ship1->Update(1);
ship1->Draw(driver, shipTexture);

(Also, the ship's texture is cut off after a while(as seen in the screenshot)).

And also, when I don't 'move' the ship (so I just change it's position once at startup (i.e. this->position.X = 100 this->position.Y = 100) then it behaves normally, so maybe there is something wrong with the way I set up everything?

the double drawing issue..

\$\endgroup\$
1
\$\begingroup\$

I managed to fix it. The problem was indeed my main loop.

What was causing the issue was that I was using the wrong driver when creating my device. My code for creating a device was this :

IrrlichtDevice *device = createDevice();

But this apparently uses the wrong video card driver, so I had to pass one manually like so:

IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(1024, 720));

This seems to have solved the issue for me!

\$\endgroup\$
0
\$\begingroup\$

This seems that the screen buffer is not being cleared.

Make sure you have something like driver->beginScene(true, true, video::SColor(255,0,0,0)); in your main loop.

\$\endgroup\$
3
  • \$\begingroup\$ Hey man, tried that but it didn't seem to help. Maybe I just need to draw it in another way:) \$\endgroup\$
    – Marciano
    Apr 16 '14 at 19:40
  • \$\begingroup\$ Mind posting your main loop? \$\endgroup\$ Apr 16 '14 at 19:46
  • \$\begingroup\$ Thanks I took another look at my main loop and found the cause of the problem:) \$\endgroup\$
    – Marciano
    Apr 19 '14 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .