c++ - SFML only draws some sprites -


i'm having strange problem 1 sprite loading isn't

here main.cpp

    window.draw(universe.getplayer()->draw());  //draw player      std::list<abstractblock*>::const_iterator i;     std::list<abstractblock*>* values = universe.getloadedblocks();      (i = values->begin(); != values->end(); ++i){         window.draw((*i)->draw()); //draw blocks     }      window.display(); 

here can see player drawing , blocks in universe drawing. however, player draws , blocks don't draw @ all. have made sure loop working. because draw() returns void can't see if working or not.

here dirtblock.cpp (i'm inheriting abstractblock)

dirtblock::dirtblock(int x, int y, float rotation, b2world *world){     bodydef.position.set(x, y);     bodydef.lineardamping = .03f;     bodydef.type = b2_dynamicbody;      fixdef.density = .1f;      b2polygonshape shape;     shape.setasbox(16, 16);      fixdef.shape = &shape;      body = world->createbody(&bodydef);     body->createfixture(&fixdef);      texture.loadfromfile("dirt.bmp");      sprite.settexture(texture);     sprite.setorigin(16, 16);   }  sf::sprite dirtblock::draw(){     sprite.setposition(body->getposition().x, body->getposition().y);     return sprite; } 

not included, stuff involved drawing.

my player class similar:

player::player(b2world *world){      texture.loadfromfile("player.bmp");     bodydef.position.set(10, 10);     bodydef.type = b2_dynamicbody;     fixdef.density = .1f;     b2polygonshape shape;     shape.setasbox(16, 16);     fixdef.shape = &shape;      body = world->createbody(&bodydef);     body->createfixture(&fixdef);     body->setlineardamping(.03f);      sprite.settexture(texture);     sprite.setorigin(16, 16);      force = 10.f;  }  sf::sprite player::draw(){     sprite.setposition(body->getposition().x, body->getposition().y);     sprite.setrotation(body->getangle() * (180 / b2_pi));     return sprite; } 

since similar why 1 drawing , other not? have feeling might because of inheritance. i'm typically java programmer , i'm not 100% sure did inheritance correctly in c++. should this? (my dirtblock.h)

class dirtblock: public abstractblock { public:     dirtblock();     dirtblock(int x, int y, float rotation, b2world *world);     ~dirtblock();     virtual sf::sprite draw();     virtual void destroy(b2world *world); private:      sf::sprite sprite; }; 

i fixed myself. turned out stupid mistake on part might write , answer if else makes mistake may find , may fix problem.

i didn't make function draw in abstractblock class virtual. because of this, when calling draw dirtblock, looking draw method in abstractblock didn't have virtual flag.


Comments

Popular posts from this blog

renaming files in a directory using python or R -

c# - ajax - How to receive data both html and json from server? -