Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Image is drawn transparent after vector resize?  (Read 2116 times)

0 Members and 1 Guest are viewing this topic.

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Image is drawn transparent after vector resize?
« on: February 27, 2010, 02:09:35 am »
Hey there,
in my game, when i blast a balloon (with an object inside of it) the object begins to drop, and the balloon that had been blasted gets a new random position (without another object). Now that i wanted to do add a new object when balloon is poped, i resized my vector <Object> and initialize it with Image, positions, etc. Now when i pop a any balloon, all objects seem not to have any image with them :roll: they appear transparent. But if i dont add that resize of the vector the game works fine (without the new object when balloon pop).
Code: [Select]
balloon[i].SetIsAlive(false);
object[i].Drop = true;
object[i].BalloonIndex = i;
GenBalloons(i, balloon);
works fine
Code: [Select]
balloon[i].SetIsAlive(false);
object[i].Drop = true;
object[i].BalloonIndex = i;
GenBalloons(i, balloon);
//-----------------
object.resize(object.size() + 1);
if (!object[object.size() - 1].Image.LoadFromFile("main\\object1.png"))
return 1;
object[object.size() - 1].Sprite.SetImage(object[object.size() - 1].Image);
object[object.size() - 1].Sprite.SetCenter(object[object.size() - 1].Sprite.GetSize().x / 2, object[object.size() - 1].Sprite.GetSize().y / 2);
object[object.size() - 1].Sprite.SetPosition((balloon[i].Sprite.GetPosition().x - object[object.size() - 1].Sprite.GetPosition().x) / 2, (balloon[i].Sprite.GetPosition().y - object[object.size() - 1].Sprite.GetPosition().y) / 2);
object[object.size() - 1].Drop = false;
object[object.size() - 1].SetIsAlive(true);
object[object.size() - 1].BalloonIndex = i;
object[object.size() - 1].SetSpeed(object[i].GetSpeed());

doesnt work fine

Window.Draw()
Code: [Select]
for (int i=0;i<BALLOONINDEX;i++)
{
//if (object[i].Drop == true  && ObjectColHand(i, object, hand) == false)
Window.Draw(object[i].Sprite);
}
while (!idle)
{
   DoSomething();
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Image is drawn transparent after vector resize?
« Reply #1 on: February 27, 2010, 01:53:37 pm »
You should read the last part of the sprites tutorial, which is about the bad things that happen when images are copied.
Laurent Gomila - SFML developer

led

  • Newbie
  • *
  • Posts: 28
    • View Profile
Image is drawn transparent after vector resize?
« Reply #2 on: March 02, 2010, 12:30:12 pm »
It's working now, thanks again :wink:
while (!idle)
{
   DoSomething();
}

 

anything