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.


Topics - ThatOneGuyThatDoesStuff

Pages: [1]
1
I set the mouse cursor to a custom one. But when the mouse cursor leaves the games window, it reverts back to Windows 7 default cursor, and doesn't go back. Is this just something I need to watch for in the code? Do I need to reset the cursor each time the cursor leaves the window and returns?

2
I load and set the mouse cursor which works as expected. But as soon as it leaves the bounds of the created window, the cursor changes back to the normal Windows 7 cursor and doesn't change back to the custom cursor if it returns into the window. Any idea why? Thanks.

3
Graphics / Scale offset
« on: June 22, 2021, 09:50:57 pm »
Whenever I have tried to scale a sprite, it offsets down slightly. It doesn't move left or right, but it's position is lower that it should be (greater y value). I have no idea why. Would appreciate an explanation as to what I'm doing wrong.

sprite.setScale(CATAPULT_SCALING_FRACTION);
 

4
Graphics / Just cannot get sf::Text to draw without crash
« on: August 23, 2020, 10:28:10 pm »
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <ioStream>

int main()
{
    sf::Text testText;
    sf::Font font;
    font.loadFromFile("cour.ttf");
    testText.setFont(font);
    testText.setString("Hello World");
    testText.setPosition(200, 200);
    testText.setCharacterSize(25);
    // Create the main window
    sf::RenderWindow renderWindow(sf::VideoMode(WIDTH, HEIGHT), "SFML window");

        // Start the game loop
    while (renderWindow.isOpen())
    {
        // Process events
        sf::Event event;
        while (renderWindow.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                renderWindow.close();
        }

        // Clear screen
        renderWindow.clear();

        // Draw sprites
        renderWindow.draw(testText);

        // Update the window
        renderWindow.display();
    }

    return EXIT_SUCCESS;
}
 

No matter what I do, I cannot get an sf::Text object to draw without the app instantly crashing. Been plagued by this problem for months. I've asked reddit, stack overflow and even here. I'm hoping for better results, because I have no idea what else to do to make it work. I have reinstalled both code::blocks and sfml. I installed sfml and Code::Blocks on a different pc, same problem. I have tried different fonts, same problem. All other SFML features function exactly as they should.

I'm using Code::Blocks v17.12 and SFML v2.5.1

If I comment out
font.setFont
, it will run (though not draw obviously). If I comment out
renderWindow.draw(testText)
it will run without a crash.

If I run debugger I get the info that the problem file is C:\Windows\SysWOW64\ig4icd32.dll. I've tried looking that up, but get nothing related to my problem.

Any help is appreciated. Also, if anyone knows a work around, I would appreciate it.

5
Graphics / texture.loadfromfile causes crash?
« on: July 07, 2020, 10:42:58 pm »
2 Textures, no different than all the others I have loaded, cause the program to crash immediately. They are private variables inside a class, and I loadFromFile() in the constructor, but trying to load from anywhere else, even in main{}, causes a crash.. I have done this with plenty other classes and textures, but these two in particular are just causing a crash. By changing them to global variables, they load fine.

Any idea why this might be happening?

6
What I want to do is create an sf::Sprite that is a compilation of a number of other given sprites/textures.

e.g. If I had 4 16x16 textures, I want to create a sprite that is 64x64 that contains those 4 smaller textures in a specific pattern. Is there any way I can do this, or something similar?

7
General / Is it possible to have an array/vector of Textures?
« on: March 17, 2020, 08:35:16 pm »
Is it possible to have an array/vector of Textures or do they have to be Sprites?

8
Graphics / Drawing text immediately crashes
« on: February 23, 2020, 10:42:20 pm »
I just... don't understand why...

I am writing a large application and after some 500 lines of code I need to draw text to the screen for the first time. And it just won't. I opened up a new project to recreate the code doing the work to try and find the problem, but it just crashes with even the bare minimum.

int main(){
  sf::RenderWindow renderWindow(sf::VideoMode(800, 600), "Test app");
  sf::Event event;
 
  sf::Font font;
  font.loadFromFile("Image/arial.ttf");
  sf::Text test ("Hello", font);
 
  while (renderWindow.isOpen()){
    while(renderWindow.pollEvent(event)){
      if (event.type == sf::Event::Closed){
        renderWindow.close();
      }
    }
    renderWindow.clear();
    renderWindow.draw(test);

    renderWindow.display();
  }
}
 

9
General / All sprites in vector are moving in the exact same pattern
« on: February 14, 2020, 10:45:51 pm »
I have been bashing my head against the wall for the last 4 days trying to figure out where in the name of holy pasta salad I'm going wrong here. I cannot begin to vent my frustration.

class AnimalObj{
    sf::Sprite animalSprite;
    void MoveAnimal(int direction){
        //Moves in the appropriate direction
        if (direction == 1){
            //Go up
            if (animalSprite.getPosition().y - animalMoveDist >= 0){
                animalSprite.move(0.0, -animalMoveDist);
                AnimateAnimal(1, 1);
                previousMove = 1;
            }
        }else if (direction == 3){
            //Go down
            if (animalSprite.getPosition().y + animalMoveDist <= 800){
                animalSprite.move(0.0, animalMoveDist);
                AnimateAnimal(3, 3);
                previousMove = 3;
            }
        }else if (direction == 2){
            //Go right
            if (animalSprite.getPosition().x + animalMoveDist <= 1000){
                animalSprite.move(animalMoveDist, 0.0);
                AnimateAnimal(2, 2);
                previousMove = 2;
            }
        }else if (direction == 4){
            //Go left
            if (animalSprite.getPosition().x - animalMoveDist >= 0){
                animalSprite.move(-animalMoveDist, 0.0);
                AnimateAnimal(4, 4);
                previousMove = 4;
            }
        }else{
            AnimateAnimal(0, 0);
            previousMove = 0;
        }
    }

std::vector<Chicken> animalArr;
int main{
    AnimalObj NewChicken;
    NewAnimal.animalSprite.setTexture(henTex);
    NewAnimal.animalSprite.setPosition(400, 400);

    AnimalObj new_chicken;
    NewAnimal.animalSprite.setTexture(roosterTex);
    animalArr.push_back(new_chicken);

    while (renderWindow.isOpen()){
        for(int animal = 0; animal < animalArr.size(); animal++){
            animalArr[animal].MoveAnimal(RandomDirection()); //RandomDirection returns a random direction
            renderWindow.draw(animalArr[animal].animalSprite);
        }
    }
}
 

I hope I didn't post too much code. I purged as much as I could that I thought was surplus/unnecessary.

The problem is that each sprite will move in the same direction, regardless of where they are going. If one goes left, all sprites go left. If it goes right... all of them go right. At first I thought it was an issue with my random number generation, but I programmed in instructions to move to a particular position for one of the sprites, and all sprites would then move in the appropriate direction, regardless of where they are spawned. Once the first sprite arrives at location, it stops moving. I've pretty much narrowed down the error to the MoveAnimal function that I posted above, but I have no idea why it's doing that. It seems that the .move() function is causing all sprites in the vector to move in the same direction despite them being told to move randomly I checked, the appropriate MoveAnimal are receiving instructions to move randomly, but are ignoring them in favor of following the direction of the first sprite until it arrives at location, then all the rest continue to move in sync.

I don't know if I'm just being incredibly dense here, but any help will be greatly appreciated. Seriously. I'd like to stop banging my head on the table, so if anyone can help me put an end to that, that would be great.

Pages: [1]