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

Author Topic: SFML Window not showing!!!  (Read 39594 times)

0 Members and 1 Guest are viewing this topic.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
SFML Window not showing!!!
« Reply #30 on: December 23, 2011, 01:16:16 am »
Quote from: "Viruses"
Ok... But how would you tell it that? Thats what im asking. Is there a special function that does opposite of:

Code: [Select]


screenameorwatever.Draw(spritename);




In this case a sprite is drawn on the screen.
But is there a function that would undraw the sprite from the screen or something?
No, there isn't. You just... don't draw it.
I use the latest build of SFML2

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #31 on: December 23, 2011, 04:37:29 am »
Make an if, and the sprite will only draw if the requeriments of the if are met.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #32 on: December 23, 2011, 10:46:00 pm »
@OniLink10

Dude you don't understand what i was saying. If you draw a sprite in a game(like in a spaceshooter) then its DRAWN. So if a bullet hits it, it DISAPPEARS and you score a point.. What your saying makes no sense... "You just...dont draw it"  you have to draw stuff for games. So is there something that undraws the sprite?

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #33 on: December 23, 2011, 10:53:10 pm »
Yes, in fact, there is. You have an if statement that checks whether the ship has been hit before drawing it.

EDIT: Oh, and if you aren't already, I recommend clearing the screen every frame and redrawing it. That's what you're supposed to do, and from what you've said it seems you aren't doing this.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #34 on: December 24, 2011, 12:37:51 am »
And how do i redraw the screen every frame? Every tutorial ive seen so far on SFML, and thats like every tutorial availible, all it does for the "set up" is it makes a while loop and checks for events. So the game loop. I dont know about how to CODE the frame thing.. And also, i cant believe i have to repeat this, I HAVE TO DRAW THE THING ON THE SCREEN AND THEN CHECK IF ITS HIT AND THEN IF IT IS, UNDRAW IT.   Please read that like 5 times and then reply. The if statement doesnt make sense because how will the user know where to hit the enemies if the user cant see it? So it has to be DRAWN first and then UNDRAWN if the enemy is hit..

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #35 on: December 24, 2011, 02:14:01 am »
Viruses, to clear the screen every frame, use
Code: [Select]
App.Clear(sf::Color(red, green, blue))
About the if, lets see everyting from another perspective:

You must re-draw the "thing" every frame that the "thing" will appear on the screen. It is possible to make an if to check if the "thing" has already been hit, and you only re-draw it if still hasn't. Simply as that.

At the beggining the "thing" will be draw because it was not hit. When it is hit, the if makes the code not draw the "thing" and the "thing" will not be on the screen anymore, since you've already cleared the screen at the start of the current loop.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #36 on: December 24, 2011, 04:19:18 am »
Okay well i always use App.Clear()... Lol. So ive been clearing the screen 60 times anyways. But i dont get the whole if statement thing you said. Ill give some example code:

Code: [Select]



while(runningstuff)
{
blah blah;

App.Clear();

App.Draw(sprite);

   if(collisiondetectioncode)
   {
     
       BUT WHAT DO I PUT HERE? Is there a function that UNDRAWS the     sprite? THATS THE WHOLE QUESTION IM ASKING!
     


   }

}





So please clarify about "undrawing" or "unloading" the sprite.

Sam42

  • Newbie
  • *
  • Posts: 16
    • View Profile
SFML Window not showing!!!
« Reply #37 on: December 24, 2011, 04:33:40 am »
The answer has been provided! You're missing the point of what everyone has been saying i'm afraid.

Every frame you blank the screen, draw whatever you want to draw, and then display it. This means that to remove something previously displayed  from the current display, you simply don't draw it anymore.

Code: [Select]

while(running)
{
// events
// logic

App.Clear(); // Blank the screen

   if(collision == false) // If there is no collision
   {
  App.Draw(sprite) // Draw the sprite
   }

   App.Display(); // Finally display what we've drawn this frame
}  


This is very simplistic, and you'll want to do a lot more than that with any actual game object, but it's the idea people have been trying to get across. You only call draw on the sprite during the frame if there is no collision, if there IS a collision, then draw doesn't get called, and the sprite will dissapear from the screen.

You don't actively undraw anything, at any point. Essentially, every frame you want to display a freshly drawn image.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #38 on: December 24, 2011, 04:48:53 am »
WOW! I get it!  I guess if the other people had provided code it wouldve been better but thank you for clearing that up. And btw, are shaders essential
or necessary for 2D games in SFML or something? Because just about everything confuses me about them. I have very limited knoweledge. So i know im going to have to learn it sooner or later but is it essential for now?

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #39 on: December 24, 2011, 06:06:56 am »
We've been trying to teach you the logic behind it, so that you can make the code on your own. Giving working code might lead you to simply copy it without learning.

By the way, you don't need to learn shaders at all if you want to use SFML only. Of course, there are things that would not be possible without them, but the basics are provided just well by SFML.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #40 on: December 24, 2011, 05:38:54 pm »
Ok thank you. I'll stick with the basics for now. There is still one thing im confused about. I know you guys might've already explained it but i dont get it at all. I tried searching it up to no avail. There is only ONE tutorial on this website on SFML 2.0 and its not even about coding. So i have no where to go. Its animation. I dont get the subrect function still. I would appreciate some code and then maybe a screenshot of what it does so that i can see with the code and explanation and screenshot what it actually does. Or if there is another way to animate, please tell me. I would not ask on this forum if i could find any tutorials on it. Thanks!

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
SFML Window not showing!!!
« Reply #41 on: December 24, 2011, 06:50:13 pm »
Lets assume that your file have 30 frames, each 100px wide and 200px tall, so your image have width = 3000px, containing all the 30 frames, and height = 200px. You want to make a transition between all these frames with duration of 1 second.

It will be someting like this in current version of SFML 2:

Code: [Select]

...

sf::Clock Timer;
int CurrentFrame = 0;

while (App.IsOpened()) {
    if (Timer.GetElapsedTime() >= 1000 / 30) {
        CurrentFrame++;
        Timer.Reset();
    }
    YourSprite.SetSubRect(sf::Rect<int>(CurrentFrame * 100, 0, (CurrentFrame + 1) * 100 - 1, 200));
    App.Draw(YourSprite);
}

...


1000 / 30 is the aproximate duration, in milliseconds, of each frame. As you can see, you must manage the time and make the correct SubRect at each game loop iteration.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #42 on: December 24, 2011, 07:52:18 pm »
I still dont get the parameters of subrect... it should only have 2 simple parameters, the width and the height, but it gives me some other crap.

Pyrius

  • Newbie
  • *
  • Posts: 39
    • View Profile
SFML Window not showing!!!
« Reply #43 on: December 24, 2011, 07:59:47 pm »
No, you need the top left point, too. Otherwise the subrect could be anywhere on the image.

Code: [Select]

sf::Sprite::SetSubRect(Left, Top, Width, Height)


Those are the parameters. By the way, although there's only one tutorial, there is documentation. That could be helpful.

Viruses

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
SFML Window not showing!!!
« Reply #44 on: December 24, 2011, 08:14:57 pm »
When i do this :    sf::Sprite::SetSubRect(0,0,60,60)     it gives me an error. Im trying to say that the subrect is in the 0,0 pixel or watever in the spritesheet and that the width and height of the subrect is 60. But it doesnt work.

 

anything