New answers tagged

2

No, you don't need to port forward the client. If the server runs on a home computer (behind a NAT) then yes, you need to port-forward the server or check out how udp-hole-punching works but if the server runs on a real server (a server you rent with a public ip-address) then it should work out of the box. Note though, the client, which is probably behind a ...


4

While not necessarily at fault here, GetSpriteByPosition returns a pointer to a temporary returned by getDrawable. You may not return pointers or references to locals or temporaries, as they do not outlast the function they appear in. As for your error, you can divine some information from the faulting address. 0xB4 is almost zero, which usually means that ...


1

SFML has a few good functions that allows you to do what you want a bit simpler window.mapPixelToCoords(sf::Mouse::getPosition(window), viewRect); That line of code will convert the mouse position relative to the window (sf::Vector2i), to a world coordinate (sf::Vector2f). I have the window as an argument there, or else it will get the mousePos relative ...


2

First off, you should really store the tiles in a 2d array. As far as I can tell from documentation, sf::View has a getViewport() method. This method gives the coordinates of the top-left point of your view. Next you will need the coordinate of the mouse, in relation to the top-left of your window. Finally, you add the two coordinates together, and you'll ...


2

Figure out your mouse position in world space and divide by the tile size. Basically keep track of where your upper left corner is in world space, add the mouse position to that (with appropriate scaling etc.) and then divide it by your tilesize.


0

The issue turned out to be a problem with the way Wayland works. My install of Gnome was defaulting to Wayland, instead of x, and Wayland doesn't do a good job of capturing the cursor within a window.


2

Your problem is this line: roomSprites[x]->setPosition(sf::Vector2f(x * 32, y * 32)); What do you think will happen in the second row? x will start at 0 again and you'll set the position of the first 10 sprites. In the third row, x will start at 0 again and you'll set the position of the first 10 sprites. See where this will end? You either have to ...



Top 50 recent answers are included