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

Pages: 1 ... 10 11 [12] 13 14 ... 25
166
Graphics / Re: text doesnt show up in app
« on: December 02, 2020, 03:06:52 pm »
the 'e' variable (Text) is destroyed when the function ends, so there is no text at all to draw.
also, you don't have a font attached to the Text. and the text itself is not being drawn to any window.

167
General / Re: Detection part of object
« on: November 27, 2020, 02:50:03 pm »
about raycasting, there it is a very good video explaining the theory:
http://www.youtube.com/watch?v=fc3nnG2CG8U

168
General / Re: Simple rotation does not work
« on: November 22, 2020, 12:27:09 am »
well, for me, when I move the mouse the square turns faster  ;D
my guess is that the default spinning speed depends on the default keyboard key delay. each signal sent by the keyboard generates one single event.
but when you move the mouse, lots of other events are also generated. and since the arrow key is being hold down, your code recognizes if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) as true and rotates the square by the number of new events generated. I don't know if I made myself clear.

anyway, if you just want to check is a key is being holded down, you don't need events for that. just move the 
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))//or Right, with the rotation commands
outside the while (window.pollEvent(event)), but keep it inside the while (window.isOpen()) loop.

169
well, that's rather strange. I was going to say that Keyboard::Enter references only the main key (Return), but I just went to the docs to search which would be the key to numpad enter and there is no mention to it. as the docs mention "Enter | The Enter/Return keys", with an "s", I'm guessing that it could be a bug  ???

170
Graphics / Re: RectangleShape Not Drawing
« on: November 17, 2020, 07:29:23 pm »
weird. are you able to draw a single RectangleShape, or a vector of rectangleshapes, directly in a small main function?



Quote
x: 295 y: 261
[Log] Shape Drawn 1
x: 295 y: 261
x: 536 y: 512
[Log] Shape Drawn 2
x: 536 y: 512
x: 793 y: 375
[Log] Shape Drawn 3
x: 793 y: 375
x: 573 y: 196
[Log] Shape Drawn 4
x: 573 y: 196
x: 442 y: 428
[Log] Shape Drawn 5
x: 442 y: 428
x: 199 y: 565
[Log] Shape Drawn 6
x: 199 y: 565
x: 142 y: 338
[Log] Shape Drawn 7
x: 142 y: 338
x: 262 y: 104
[Log] Shape Drawn 8
x: 262 y: 104
x: 807 y: 98
[Log] Shape Drawn 9
x: 807 y: 98
x: 1030 y: 191
[Log] Shape Drawn 10
x: 1030 y: 191
x: 1077 y: 476
[Log] Shape Drawn 11
x: 1077 y: 476
x: 810 y: 603
[Log] Shape Drawn 12
x: 810 y: 603
x: 515 y: 86
[Log] Shape Drawn 13
x: 515 y: 86

171
Graphics / Re: RectangleShape Not Drawing
« on: November 17, 2020, 01:42:25 pm »
no, I mean things like pragma once and include "Shapes.h"

I just put all together in a single source file:

#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>

struct Box {
        sf::RectangleShape sprite;

        Box() {
                sprite.setSize(sf::Vector2f(100.f, 100.f));
                sprite.setFillColor(sf::Color::Red);
                sprite.setPosition(0, 0);
        }
}shape_box;
std::vector<Box> shapes;

void logVec2f(const sf::Vector2f& vec) {
        std::cout << "x: " << vec.x << " y: " << vec.y << std::endl;
}

void logMousePosRelToWin(sf::RenderWindow& Win) {
        std::cout << "x: " << sf::Mouse::getPosition(Win).x << " y: " << sf::Mouse::getPosition(Win).y << std::endl;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(1200, 800), "Gravity Box");


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            if (event.type == sf::Event::MouseButtonPressed) {
                shape_box.sprite.setPosition(sf::Vector2f(sf::Mouse::getPosition(window)));
                shapes.push_back(shape_box);
                logMousePosRelToWin(window);
                std::cout << "[Log] Shape Drawn " << shapes.size() << std::endl;
                logVec2f(shape_box.sprite.getPosition());
            }
        }

        window.clear();
        for (unsigned int i = 0; i < shapes.size(); i++) {
            window.draw(shapes[i].sprite);
        }

        window.display();
    }

    return 0;
}

 

172
Graphics / Re: RectangleShape Not Drawing
« on: November 17, 2020, 11:46:13 am »
I just tested your code (i've put everything in the same source file, except from preprocessors) and its working as it should...

173
General / Re: Problems with Text
« on: November 17, 2020, 11:34:36 am »
if this is all your code, you forgot to create the RenderWindow inside main:
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

174
clearing and drawing to the window should be done every loop. you have this:
window.clear(sf::Color::Black);
changeDirections(snake, state);
snake.draw(window);
inside this while loop:
while (TIME_PER_UPDATE <= timeTaken)
meaning that the window will be cleared and the snake drawn only when this loop runs, which isn't every time. try to move window.clear(sf::Color::Black); and snake.draw(window); to just above window.display();, like this:

                        changeDirections(snake, state)
                }
window.clear(sf::Color::Black);
snake.draw(window);
window.display();

175
Graphics / Re: Help with drawing NQueens problem using 2D arrays of objects
« on: November 06, 2020, 03:43:20 pm »
probably unrelated to SFML, but actually to C++ itself.
check trough the debugger the values of "queen.getRow()", "queen.getCol()", and the size of "boxes" inside the adQueen function.

176
Graphics / Re: Sprite fail to load when creating multiple objects
« on: November 06, 2020, 03:38:12 pm »
i didn't checked all possibilities, but first you should check if the texture is being loaded at all. something like:
if (this->texture.loadFromFile("queen.png") == false) std::cout << "texture not loaded";

another thing (probably unrelated to the problem) is that each instance of your class has its own texture, but all textures are the same. one of the points in using textures is that you can reuse it in more sprites. maybe you could make this texture static?

177
Graphics / Re: Help with drawing NQueens problem using 2D arrays of objects
« on: November 05, 2020, 11:37:26 am »
have you tried debugging it? so you can at least know in which line the problem starts?

178
Graphics / Re: Scrolling tilemap issue: black bars
« on: November 05, 2020, 12:39:54 am »
a) As the tilemap is drawn on the complete screen anyway, I could just omit the clearing of the rendertarget.
i'm almost sure that it could lead to some artifacts anyway (they just aren't going to be black)

b) Make sure the view position is only set to integer positions instead of pixel positions.
i think that its not on the view, but mainly the tiles positions. try to position them with integers instead of floats.

179
Window / Re: Window not showing anymore
« on: October 25, 2020, 03:13:51 am »
I don't really know why you are trying to use new in that case, but try
sf::RenderWindow g_window(sf::VideoMode(1080, 720), "MyGame");

180
General / Re: Pathfinding script
« on: October 24, 2020, 03:44:37 pm »
well, you won't find anything as "pathfinding script" for SFML, since it is a library for C++, a language that is not scripted. so, its different from a game engine like Godot or Unity.

to be honest, the backbones of a pathfinding code doesn't need SFML at all. have a look at this: https://www.redblobgames.com/pathfinding/a-star/introduction.html

of course, you'll need some programming knowledge.

Pages: 1 ... 10 11 [12] 13 14 ... 25
anything