New answers tagged

2

You should not have if-statements nor case-statements; at least not nearly so many. The immediate problem is that you're hard-coding a bunch of logic where a data-driven approach would work better. What you have here on first glance is a state graph (or a finite state machine). Rebuilding this as a state graph with inputs triggering transitions would be a ...


0

There must be some transformation you're applying to rendered primitives.It doesn't matter if you give integer coordinates to text line, if later some transformation will make those coordinates fractional. To have sharp texts, you must get text line primitive's texels fit exactly into screen pixels, after all transformations was applied. That might even ...


0

You are using absolute positions in world space to detect "in bounds" or "out of bounds" on a 2D xy axis plane. It would be easier and less code to do line intersect testing where each wall is two points connected by a line and your collision testing line intersections with your player line of motion. That line of motion can be current position and ...


0

First off, I would suggest using power of two dimensions for your texture, it's not required, but more efficient. sf::Sprite has a function "void setTextureRect(const sf::IntRect& rectangle)" which you can use to specify a sub-rectangle of the texture that sprite will display. sf::IntRect has a few options to be created, generally it wants the ...


2

You are totally on target. One approach would be to return an integer which is the index of which one you hit, and a "special value" if nothing was hit. So: int Stage::checkForStageCollisions(sf::RectangleShape player) { ... return i; ... return -1; } Elsewhere you could say, if(checkResult >= 0) [something was hit]. Or do ...


1

Rather than loading and unloading the textures on a per-frame basis, one possibility would be to load all the frames for a certain animation at once. For example, if you're about to play the attack animation, load all the frames for the attack animation(s) into memory if they aren't already there (checking whether the animation already exists in memory would ...


0

Okay I have found the answer and for those who might be looking through suffering the problem as well I will by trying to write fairly generic code that should be easy to read. Any issues post as a comment and I will answer as best as I can. Anyway it turns out that the problem was I was trying to use glBufferData before using glBindBufferwhich lead to the ...


0

When storing items of a child class in a vector, the vector will call the father's constructor (constructor of the type the vector was appointed to.) To avoid that, you'll want a vector of pointers instead: std::vector<DrawableEntity *> entites; For this approach you will likely have to dynamically allocate your entities manually using, say, the ...



Top 50 recent answers are included