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 - aradarbel10

Pages: [1]
1
General / Using SFML in a static library project
« on: March 22, 2021, 10:41:09 pm »
I'm trying to set up a static library for personal use, and I'd like to use SFML functionality in it.
I think I've done everything needed for it to work:

Configuration Properties > C/C++ > General > Additional Include Directories
Configuration Properties > Librarian > General > Additional Library Directories
Configuration Properties > Librarian > Genera > Additional Dependencies
Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions (for static linking)

IntelliSense does recognize SFML, yet the project throws many errors on build. For example
cannot open source file "algorithm". this specific error comes from Rect.hpp, part of SFML itself. On top of that there are many other similar errors related to C++ STL, many of them come from String.hpp. What did I do wrong?

Any help is appreciated

2
General / getting rid of the dlls
« on: August 20, 2018, 02:30:16 pm »
Hello,
Let's say that I have a project executable that is all working. SFML is linked dynamicly. I want to get rid of the dll's, by either linking sfml staticly or moving them into a sub folder in the .exe directory. I have no idea how to do nor, can anyone help me? I want to know which one of them is better for a piece of software that will be available to download (this should run on almost any computer).

Any help will be appreciated,
Arad.

3
Graphics / Vector Of Calsses with textures / White Rectangle Problem
« on: July 19, 2018, 11:14:19 am »
Hello,
You probably know what is the problem of mine: I have a vector of button objects (class). each button contains a rectangleShape and its texture (I know I can use a sprite). the texture appear to be a white rectangle. in the past everything worked but now its not. I know its a pointer problem, but don't know how to fix it, or how to use the puch_back correctly to make it work. here is the class:

void Button::setButton(float x, float y, float w, float h) {
        pos = sf::Vector2f(x, y);
        size = sf::Vector2f(w, h);
}

void Button::setTexture(string dir, sf::Vector2f s) {
        textureDir = dir;
        buttonTexture.loadFromFile(textureDir);
        button.setTexture(&buttonTexture);

        if (!textureLoaded) textureLoaded = true;
}

void Button::setMode(bool m) {
        mode1 = m;
        modeList.push_back(mode1);

        int temp = 0;
        for (int i = 0; i < modeList.size(); i++) {
                if (modeList[i]) temp++;
        }

        if (temp != 0) {
                buttonMode = true;
        }
        else {
                buttonMode = false;
        }
}

bool Button::getMode() {
        return buttonMode;
}

void Button::update() {
        button.setPosition(pos);
        button.setSize(size);

        if (dimention == 0) {
                texturePos.x += 128;
        }
        else {
                texturePos.x += 0;
        }

        if (buttonMode) {
                texturePos.y = 64;
        }
        else {
                texturePos.y = 0;
        }

        modeList.clear();

        cout << pos.x << " " << pos.y << " , " << size.x << " " << size.y << endl;

        button.setTextureRect(sf::IntRect(texturePos.x, texturePos.y, size.x, size.y));
}

sf::RectangleShape Button::getShape() {
        return button;
}

void Button::show(sf::RenderWindow &window) {
        window.draw(button);
}
 

and the buttons are controlled by another class that maneges everything in the current level of the game (probably the issue occures in this function, because it's the only one that related to the buttons except for a functions to change the mode of the button when clicked, and I am not calling this one anywhere in the code):

void Level::newButton(float x, float y, float w, float h, string dir) {
        button1.setButton(x * tileSize.x, y * tileSize.y, w * tileSize.x, h * tileSize.y);
        cout << "p: " << x << " * " << tileSize.x << " , " << y << " * " << tileSize.y << endl;
        button1.setTexture(dir, sf::Vector2f(w, h));
        buttonSet.push_back(move(button1));
        cout << "New Button Added" << endl;
}
 

and it is also important to say that you can see the texture on the button in the first frame, but after that it becomes white.
From what I knwo I may want to create a vector of pointers, but I don't know how to do it.

any help will be appreciated,
Arad.

4
General / Re: player-wall collision in game
« on: June 13, 2018, 04:40:52 pm »
Detecting collision is (genenrally) testing to see if two things are overlapping. However, the response to collision is what you do what that occurs.

One thing to do is, as you've done, stop the thing from moving anymore if they collide. However, this means that they stop where they are overlapping. Generally, and especially for things like walls, you want to move the thing to where it should be - outside of the wall. There are different approaches to this and I don't profess to know lots about this.

One approach is to move is back to where it was before it collided. This is the easiest step and could be the best solution depending on how accurate you want it to look and how fast the thing is moving.

The next approach would be to take the previous position and the colliding position and use geometry to project the first position towards the second to work out where it would have collided between the two.

A more advanced approach could be to take the previous approach and the work how much further it would've travelled to the colliding position and 'bounce' the thing from the wall by that much. You should probably take into account the direction of travel and angle of the wall for this. However, this is less useful for things that should stop when hitting a wall. ;D

Thank you very much for your reply :)
I think I will go with the first option because its the best for my case: the player is moving in a constent velocity, and I don't need to calculate anything about the direction because there are only 4 of them (up, down, left and right).

unluckily, it does not work.

this is my code:
for (int i = 0; i < lvl.getSizeInTiles().x; i++) {
        for (int j = 0; j < lvl.getSizeInTiles().y; j++) {
            if (lvl.getTileFromBuffer(i, j).getType() == "wall") {
                if (intersects(lvl.getTileFromBuffer(i, j).getPosition().x, lvl.getTileFromBuffer(i, j).getPosition().y, lvl.getTileFromBuffer(i, j).getSize().x, lvl.getTileFromBuffer(i, j).getSize().y)) {
                    if (faceDirection == "UP" && vel.y < 0) {
                        collidesUp = true;
                        pos.y += walkSpeed;
                        vel.y = 0;
                    }
                    else {
                        collidesUp = false;
                    }

                    if (faceDirection == "DOWN" && vel.y > 0) {
                        collidesDown = true;
                        pos.y -= walkSpeed;
                        vel.y = 0;
                    }
                    else {
                        collidesDown = false;
                    }

                    if (faceDirection == "LEFT" && vel.x < 0) {
                        collidesLeft = true;
                        pos.x += walkSpeed;
                        vel.x = 0;
                    }
                    else {
                        collidesLeft = false;
                    }

                    if (faceDirection == "RIGHT" && vel.x > 0) {
                        collidesRight = true;
                        pos.x -= walkSpeed;
                        vel.x = 0;
                    }
                    else {
                        collidesRight = false;
                    }
                }
            }
        }
    }
}
 

I hope it will help you, but if you have questions about the code; just ask me.

Thank you very much again,
Arad.

5
General / player-wall collision in game
« on: June 13, 2018, 12:06:10 pm »
Hello!
my friend and I are creating a top down puzzle game, and we have an issue with the walls.
When the player is walking into a wall, it stops (which is good), but then, it gets bad.
Let me give you an example:
  the player is moving right, and suddenly hitting a wall.
  the player stops by velocity.x = 0;
  while(1 = 1){ //do it forever
    I am clicking up and the player moves 1 pixel upwards.
    I am clicking rights and the player moves 1 pixel rightwards.
    This happens until the player moves all the way through the wall.
  }

So, I hope you got my explenation... I used a while loop to tell you that I am doing these actions forever, but remember that its not accualy part of the code.

also, when I am walking right and hitting a wall, if I am tring to move up or down the player is moving only 1 pixel, and then stop and I cant move it anymore to this direction.

And now for the question. Can you share a code of rectangle collision with walls and players?
I dont have a code at all so I need to see a working example/ a tutorial for this subject.

Thanks for any help,
Arad.

6
General / Exporting a final project
« on: April 29, 2018, 10:02:50 pm »
Hello, I know that my question wes asked too many times before, but I still need help with this.
As I mentioned in the title, my question is how do I export/build my c++ project with SFML to get an .exe file?
I heard that I have to include SFML statically, but I don't know how to do it. Also, I have extra files for the textures, so I will probably need a date folder. I want the program to be runnable on any computer.
Can you explain the full steps? That's my first time doing something like that so I don't know almost nothing.
Also links to external sources will be helpful too.

Thanks for ANY help,
Arad.

Pages: [1]
anything