1
Window / Drawing sprite while passing ByRef RenderWindow
« on: June 12, 2014, 10:00:47 am »
The problem is that if I pass the RenderWindow ByRef to function I don't see the bullet but if I create the bullet in main.cpp I see the bullet, on debug i see that the programs enter in BULLET DRAWING and generates NO error, here is the piece of code:
in Main I have
in Main I have
while (window.isOpen())
{
ControlKeyPress(&window, &event);
window.clear();
window.draw(game.getBACKSprite());
window.draw(me.retPlane());
me.DrawBullets(&window);
window.display();
}
The draw function is :{
ControlKeyPress(&window, &event);
window.clear();
window.draw(game.getBACKSprite());
window.draw(me.retPlane());
me.DrawBullets(&window);
window.display();
}
void MyPlayer::DrawBullets(sf::RenderWindow *window){
int usB = 0;
for (int i = 0; i < 6; i++){
if (!this->bullet[i].isDead()){
window->draw(this->bullet[i].retBullet()); // BULLET DRAWING
usB++;
}
}
this->usingBullet = usB;
};
sf::Sprite Bullet::retBullet(){
if (!this->dead){
if (this->posX <= 800 - this->MoveVelocity)
this->posX += MoveVelocity;
else
this->dead = true;
this->bulletSprite.setPosition((float)this->posX, (float)this->posY);
}
return this->bulletSprite;
};
int usB = 0;
for (int i = 0; i < 6; i++){
if (!this->bullet[i].isDead()){
window->draw(this->bullet[i].retBullet()); // BULLET DRAWING
usB++;
}
}
this->usingBullet = usB;
};
sf::Sprite Bullet::retBullet(){
if (!this->dead){
if (this->posX <= 800 - this->MoveVelocity)
this->posX += MoveVelocity;
else
this->dead = true;
this->bulletSprite.setPosition((float)this->posX, (float)this->posY);
}
return this->bulletSprite;
};