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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - synok

Pages: [1] 2
1
Graphics / Re: Using SFML with ImGui and the NewFrame issue
« on: September 16, 2019, 06:28:23 pm »
void updateWindow(_GAME *pGame)
{
   
    while (window.isOpen()) {
        sf::Event event;
       
        while (window.pollEvent(event)) {
            // Process ImGui along with the SFML event
           
            ImGui::SFML::ProcessEvent(event);
           
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            // ImGui::EndFrame(); ????? <- shouldn't be called!
        }

        ImGui::SFML::Update(window, dt);

        ...
        // call LogonWindow here
 
        window.clear(sf::Color::Black);
 
        //window.clear(sf::Color::Black);
       
        ImGui::SFML::Render(window);
        window.display();
       
    }
 
    ImGui::SFML::Shutdown();
}
 

Thank you! I noticed I messed up ImGui::SFML::Update. Everything works fine now :)

Solution: If someone stumbles upon the same issue in the future, please refer to Elias Daler's code snippet above.

2
Graphics / Re: Using SFML with ImGui and the NewFrame issue
« on: September 16, 2019, 04:53:40 pm »
Thanks for your replies! The code is structured up in different classes, but I guess this is the part you are wondering about https://pastebin.com/rS7nuish

The commented ImGui::NewFrame() is where I suspected it to be. But repositioning everywhere in the code it did not help. As I said, before I did not really need it for whatever reason, and I have working compiles of the code to prove it. Not sure why it seems to be such a big issue now.

Edit: Here is where I use ImGui https://pastebin.com/cvHJmzVy

3
Graphics / [SOLVED] Using SFML with ImGui and the NewFrame issue
« on: September 16, 2019, 02:00:21 am »
Hello!

I have been working a while on something with ImGui in SFML. Everything seems fine so far until one day I am randomly stumbling upon issues with it. Appearantly it is related to ImGui::NewFrame not beeing called properly. I can't remember that I ever had to call it at all. Anyways, I followed the code from the examples here:

https://github.com/eliasdaler/imgui-sfml

As I said, it worked fine before. But now, out of the blue, it asks me if I have called ImGui::NewFrame; which is odd. Since I do not handle the setup of the window everyday, or everytime I work on it, I cannot remember where it would be, also since I optimized a lot of the code.

I have previously added commits that have been working fine and tested onto Github, but now when I pull one of the commits from there to try out, I face the exact same error. Everything compiles fine, but I stumble on the assert errors when I run it. Debugging simply leads me to a comment that says "Did you forgot to add ImGui::NewFrame;?"

No I didnt forget it, I just never really had to.

Anyone having any idea, it would be great. I will try different things here to come up with a solution.

4
Graphics / Re: Click on a sprite
« on: April 16, 2013, 08:51:43 pm »
I agree. Thank you for the snippet! :-)

5
Graphics / Re: Click on a sprite
« on: April 16, 2013, 07:57:39 pm »
I want to make something clear.

Avoiding the question by ridiculing it does not solve my problem. I have tried to specify what you asked, with no solution, that is why I specifically logged in and asked here. If you are a serious user of this community, provide something useful that I did not manage to find instead of pointing out that tons of this information already exists.

6
Graphics / Re: Click on a sprite
« on: April 16, 2013, 06:06:52 pm »
I tried searching, but did not find anything relevant.

if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
        // Here is where it checks if the mouse is inside the rectangle / sprite.
}

I need to click a sprite and have things happen when I do.

7
Graphics / Click on a sprite
« on: April 16, 2013, 05:59:21 pm »
Hello everyone,

I am using SFML 2.0 to try to click on a sprite. Tried using IntRect, Vector2, etc with no avail. All I need is
a simple way to click on an image. I tried googling like crazy with no results either.

The idea is if the mouse has been pressed, it needs to check if you are within a rectangle. If so, the button is clicked. Else, nothing will happen.

Thanks,

8
Graphics / Re: SFML and Sprites
« on: December 26, 2012, 03:31:20 am »
All I did now was changing the typo you made and it worked, although the animation didnt loop so all I added was
Code: [Select]
clock.restart(); when the frame reaches 6.

While were at it, I do not understand why the text kind of "blinks". I added
Code: [Select]
window.draw(text); in the event of where the mouse button is pressed. This should render the text only, I guess.

9
Graphics / Re: SFML and Sprites
« on: December 26, 2012, 12:43:13 am »
As I suspected, your sprite sheet has an extra of transparent pixels, and you start your rect with 22 as a left parameter, when it should be 0 so that it starts with the left-most sprite. In your eight setTextureRect call it falls apart, causing your blinking.

I recommend you use an index for it. You don't need to manually set the rect each time, you can use an index to multiply and you can reduce 8 if's to 1. The index would start in zero and would increase according to time.

This:


if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
                        // Animate Player to walk.
                        if(clock.getElapsedTime().asSeconds() >= 0.05f)
                                playerSprite.setTextureRect(sf::IntRect(22,1,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.1f)
                                playerSprite.setTextureRect(sf::IntRect(42,1,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.15f)
                                playerSprite.setTextureRect(sf::IntRect(62,2,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.2f)
                                playerSprite.setTextureRect(sf::IntRect(82,2,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.25f)
                                playerSprite.setTextureRect(sf::IntRect(102,1,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.3f)
                                playerSprite.setTextureRect(sf::IntRect(122,1,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.35f)
                                playerSprite.setTextureRect(sf::IntRect(142,2,18,40));
                        if(clock.getElapsedTime().asSeconds() >= 0.4f){
                                playerSprite.setTextureRect(sf::IntRect(160,2,18,40));
                                clock.restart();
                        }
                        charPosX+=.45f;
 

Can turn into:

const float timeInterval = 0.05f;
sf::Time T = sf::seconds(timeInterval);
unsigned i = 0;

if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
    // Animate Player to walk.
        if ( i > maxRows )
    {
                i = 0;
                T = sf::seconds(timeInterval);  
        }  
       
    if(clock.getElapsedTime().asSeconds() >= T)
    {
        playerSprite.setTextureRect(sf::IntRect(i * width, currentColumn * height, width, height));
        ///currentColumn is an index that starts in 0 and increases however you may want it to.
        ++i;
        T = sf::seconds(i * timeInterval);
    }
}
 

As a small sample. That way it becomes more manageable and not dependent on magical numbers. You can use the index as a static variable in a function if you use that algorithm only for said sprite, as it exists only once per program run and it won't be called for any other animation of any other object, else you have the animation index as a class member once you take it all out of main.

Quote
Because the text should be displayed if the mouse is pressed, at the moment.

The display call should always be outside of the event loop. The reason you don't call
display(object);
is because the display function exists for everything that is getting drawn, not just that one object.

I tweaked your code, and got it to:

Code: [Select]


const float timeInterval = 0.05f;
sf::Time T = sf::seconds(timeInterval);
unsigned i = 0;

// Animate Player to walk.
if ( i > 7 )
{
i = 0;
T = sf::seconds(timeInterval); 

   

{
playerSprite.setTextureRect(sf::IntRect(i * 21, 0 * 42, 21, 42));
///currentColumn is an index that starts in 0 and increases however you may want it to.
i++;
T = sf::seconds(i * timeInterval);
        }


Edit: Noticed I have put the definition of the variables in the loop. That's why. Now, he animates very fast, is there a solution to solve that? Might add that I had to set your variable "T" in the:

Code: [Select]
if(clock.getElapsedTime().asSeconds() >= 0.05f) case since I had the following error:
Quote
error C2678: binary '>=' : no operator found which takes a left-hand operand of type 'float' (or there is no acceptable conversion)
in Visual Studio. I am guessing that T is causing the delay I am looking for in this place.

10
Graphics / Re: SFML and Sprites
« on: December 22, 2012, 11:19:42 pm »
Because the text should be displayed if the mouse is pressed, at the moment.

11
Graphics / Re: SFML and Sprites
« on: December 22, 2012, 12:41:17 pm »
Oh okay, so what can I do about it? Also, I have noticed when I draw some text, that it also flickers. I am calling it when a mouse button is pressed in a specific area. I think it has something to do with window.display(), but im not sure.
You need to provide code, so we can figure out what's going on. As for now we can only guess around the thousands of different possible mistakes or errors and won't really get to an result. ;)

Sorry if I am a bit late, but here is a snippet of code of the animation on keypress:

Code: [Select]

if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::D)
playerSprite.setTextureRect(sf::IntRect(2,2,18,40));

if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
// Animate Player to walk.
if(clock.getElapsedTime().asSeconds() >= 0.05f)
playerSprite.setTextureRect(sf::IntRect(22,1,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.1f)
playerSprite.setTextureRect(sf::IntRect(42,1,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.15f)
playerSprite.setTextureRect(sf::IntRect(62,2,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.2f)
playerSprite.setTextureRect(sf::IntRect(82,2,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.25f)
playerSprite.setTextureRect(sf::IntRect(102,1,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.3f)
playerSprite.setTextureRect(sf::IntRect(122,1,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.35f)
playerSprite.setTextureRect(sf::IntRect(142,2,18,40));
if(clock.getElapsedTime().asSeconds() >= 0.4f){
playerSprite.setTextureRect(sf::IntRect(160,2,18,40));
clock.restart();
}
charPosX+=.45f;

And the spritesheet I am using is looking like this:



With dimensions of 200x100. Looking to extend the spritesheet later. The "clock" is as you guessed it, a sf::Clock, and the charPosX variable is a float to define the current position of the character.

So the result is a walk animation that blinks for a frame at the end. Same goes with the Text which has alot of unoptimized code, but here it is:

Code: [Select]
if(mouse.getPosition().x<=460&&mouse.getPosition().x>=400){

if(mouse.getPosition().y<=520&&mouse.getPosition().y>=420){
checkFridge=true;
if(checkFridge == true){
useLabelSprite.setTexture(useLabel);
useLabelSprite.setPosition(mouse.getPosition().x-10,mouse.getPosition().y-50);
useLabelSprite.setScale(2.0f,2.0f);

if(event.type==sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left){
text.setPosition(charPosX,charPosY-20);
window.draw(text);
window.display();

}else if(event.type==sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left){
text.setPosition(charPosX,charPosY-20);
window.draw(text);
window.display();
}
}
}else{
// Unload UseLabel.
checkFridge=false;
useLabelSprite.setScale(0.0f,0.0f);
}
}else{
// Unload UseLabel.
checkFridge=false;
useLabelSprite.setScale(0.0f,0.0f);
}

Thanks for any help.

12
General / Re: Running everything in Main.
« on: December 20, 2012, 11:58:07 am »
I am using C++ at the moment. And it started with coding inside the main function, since my game loop was there. And I just kept on adding more and more code without structuring it, so now it is a mess probably.

13
General / Running everything in Main.
« on: December 20, 2012, 11:19:16 am »
Well, how safe do you think it is? Is there any noticable changes if you have alot of code inside the Main function or the While loop inside of it, or is it better (not only structure-wise) to divide all functions in to headers and calling them seperately?

Anyone noticed any slow-downs or other bieffects of putting alot of game code inside one main file with one main function and one while loop that runs?

14
Graphics / Re: SFML and Sprites
« on: December 20, 2012, 11:14:36 am »
Oh okay, so what can I do about it? Also, I have noticed when I draw some text, that it also flickers. I am calling it when a mouse button is pressed in a specific area. I think it has something to do with window.display(), but im not sure.

15
Graphics / Re: SFML and Sprites
« on: December 19, 2012, 06:48:47 pm »
Yeah, well, what I want is it to draw the first texture rectangle at key pressed, then wait for a few frames, then move the texture rectangle to draw the second frame in the spritesheet, and repeat.

Does it matter where I define sf::Clock? Inside or outside loops for example.

Edit: Everything seems to work now. Thanks eXplo0it3r for your guidance. There is just one small thing left. In the end of the walk cycle he blinks for a small moment, then continues to loop when you hold down the button to move him. Why does he blink? It is like he goes transparent for a frame or so then continue to animate as normal.

Pages: [1] 2
anything