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

Author Topic: sprite being drawn twice on top of each other?  (Read 1881 times)

0 Members and 1 Guest are viewing this topic.

mastodona7x

  • Newbie
  • *
  • Posts: 21
    • View Profile
sprite being drawn twice on top of each other?
« on: July 08, 2012, 02:26:00 pm »
Hi all, I have a strange problem where in my bomberman type game I'm making, when you lay a bomb, it appears very rough around the edges. Testing in photoshop it looks like the png is being layered on top of its self twice on the window.draw(*bomb). I can tell this because the flame which is semi transparent is very dark compared to just manually placing the bomb on the field. (See pic please - I've enlarged this to make it clearer).
Has anyone come across this before and/or could suggest why this might be happening? I have tested and know only 1 bomb is being layed when space bar is pressed, so why the double texture?

Note the left bomb is a sprite I manually created and placed , the right one is one "layed" in the game by pressing spacebar, and as I say it is only 1 object...


mastodona7x

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sprite being drawn twice on top of each other?
« Reply #1 on: July 08, 2012, 02:31:44 pm »
And some code if it helps....

spacebar event
if (event.type == sf::Event::KeyPressed)
    {
                if (event.key.code == sf::Keyboard::Space)
                {
                        if(allowBomb==1)
                        {
                                Bomb bomb(-32,-32,96,96,player1.getPosition().x,player1.getPosition().y); // -1 and 34 so collision rect overlaps/collides with vBlocks next to bomb
                                bomb.setTextureRect(sf::IntRect(0,0,32,32));
                                bomb.setTexture(bombTexture);
                                vBombs.push_back(bomb);
                                fuseSound.play();
                                allowBomb=0;
                        }
                }
    }
 

this is the main game loop where the bomb is displayed (most of this is irrelevant to this but for the bomb parts)...I just thought it odd the blocks are displayed in a loop too
Code: [Select]
window.draw(vBlocks[i]) and they dont appear to be rough round the edges like the bomb is?
for (unsigned int i = 0; i != vBlocks.size(); i++) {

                        if(player1.isCollidingWith(vBlocks[i])){
                                player1.collide(vBlocks[i]);
                        }

                for (itBomb = vBombs.begin(); itBomb != vBombs.end(); itBomb++)
                {      
                        if(itBomb->getBombTimer()>1){
                               
                                if(itBomb->isCollidingWith(vBlocks[i])){
                                        //check if indesctructable
                                if(vBlocks[i].isDestructable!=true)
                                {
                                        //otherwise remove block
                                        vBlocks.erase(vBlocks.begin()+i);
                                }

                                //check if player in blast
                                if(itBomb->isCollidingWith(player1))
                                {
                                        cout<<"player 1 is dead";
                                }

                                }
                                if(itBomb->getExploded()==false)
                                {
                                        boomSound.play();
                                        itBomb->setExploded();
                                        allowBomb=1; // allow the laying of another bomb now
                                }

                                if(itBomb->getBombTimer()>2)
                                {
                                        itBomb=vBombs.erase(itBomb);
                                        break;
                                }
                       
                        }else{
                        window.draw(*itBomb);
                        }
                        }
                        window.draw(vBlocks[i]);
                }

                window.draw(player1);
                window.draw(sprite); // this is a test bomb...remove!
                window.display();
 

mastodona7x

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: sprite being drawn twice on top of each other?
« Reply #2 on: July 08, 2012, 03:21:28 pm »
OK I AM STUPID!!!  ;D Thanks to DrSulfurious in thew chat room for pointint it out (its just because I was drawing the bomb in the i loop so it was being drawn i times in the same place...I've moved the bomb drawing into a new for loop outside the main i for loop and its all fine now....I didn't get much sleep last night OK  :o ;D ;)

 

anything