sfml

Get X and Y offset of sf::View

拈花ヽ惹草 提交于 2019-12-11 07:57:07
问题 How can I get the X and Y offset of sf::View, I'm using sf::View as my 2d camera so when I click the mouse I get the mouse X and Y coords of the tile I'm clicking on void LMButtonDown(int mX, int mY) { printf("[%d][%d]\n", mX / TILE_SIZE, mY / TILE_SIZE); } This is great, but once I move the camera sf::View the coords, as expected dont take into account the sf::View offset. I dont see any function to get X or Y in the Documentation so I can take into account for the offset. Any help with this

Using MinGW to compile a SFML project

这一生的挚爱 提交于 2019-12-11 07:08:21
问题 Okay, so I have a C++ project that uses SFML, and I want to be able to compile it from the CMD using MinGW. I have it so I can compile.cpp's, however, I just need to know what more I have to do in order for it to work with SFML. I tried compiling it with CodeBlocks and MinGW, and it works fine, until I try to run it, at which point it tells me that sfml-system.dll is missing from my computer. Does this mean I installed it incorrectly? I followed the CodeBlocks installation down to the letter,

Tilemap Collision SFML C++

好久不见. 提交于 2019-12-11 06:58:46
问题 I've spent many frustrating hours and cannot figure this out, i understand collision and have it working until i try to implement gravity, i cant seem to set the player position after it hits the tile map, falling through the ground is my problem, x axis a variation of the following code works fine if (background.colMap[tiles[i].y][tiles[i].x] == 1) { playerSpeed.y = -0.f; playerSprite.setPosition(playerSprite.getPosition().x, playerSprite.getPosition().y - 1); inAir = false; } I though by

c++ sfml array[5] of strings in for loop window.display, only showing line 1,3,5

瘦欲@ 提交于 2019-12-11 06:45:45
问题 You will have to forgive me if I can't explain myself properly, I am trying to create a highscore table using c++ sfml string array. I tried drawing them separately using window.draw(array[1],array[2] and so on. But if I put the array in a for loop and use an int variable, it only draws array 1, 3 and 5. for(cnt = 0;cnt <5;cnt++) { thiswindow.draw(topscores[cnt]); thiswindow.draw(topnames[cnt]); thiswindow.display(); } 回答1: Take the display out of the loop. This should fix the problem. 回答2:

error C2228: left of '.x' must have class/struct/union

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:16:30
问题 I am getting the error and have absolutely no idea why! //create a circle shape. sf::CircleShape shape; shape.setRadius(25); shape.setFillColor(sf::Color(100,250,250)); //circle collision geometry circle circleTest(shape.getPosition.x,shape.getPosition.y,shape.getRadius()) Circle is the class for circle collision geometry.And it fails on the constructor (shape.getPosition.x,shape.getPosition.y,shape.getRadius()) I don't know why i got the error , it worked fine then all of a sudden gave me

How to check if point belongs to ConvexShape?

馋奶兔 提交于 2019-12-11 06:07:23
问题 I wrote map editor to my platform game. I'm using SFML. Map consists of polygons - ConvexShapes. I need to add selection of ConvexShapes by clicking on them. I know that I can use cv.getLocalBounds() to obtain rectangle and next check that but I need more precise solution. How to check if clicked point belongs to any shape? 回答1: Based on question comments link, this is what I got. Using the algorithm described there, we could determine if a given point is inside a shape counting how many

Copy RenderTexture to Image

点点圈 提交于 2019-12-11 05:07:44
问题 I'm trying to copy sf::RenderTexture (with sf::Image & sf::Text on it), to Opencv Mat object. We can convert an sf::Image to cv::Mat (Opencv) by sf::Image img; cv::Size size(img.getSize().x, img.getSize().y); cv::Mat mat(size,CV_8UC4, (void*)img.getPixelsPtr(), cv::Mat::AUTO_STEP); cv::cvtColor(mat, mat, cv::COLOR_RGBA2BGRA); as far as I know, in SFML we cannot add text directly to sf::Image but we have to use RenderWindow or RenderTexture for that. I guess only workaround is to load objects

Function not working as intended?

跟風遠走 提交于 2019-12-11 04:18:21
问题 First off I'd like to say I'm still a complete novice when it comes to Programming, and I've already searched for an answer to this problem, thing is, I'm not sure what's wrong. I wrote a function to set parameters for an sf::Text object: void FontParam(sf::Text obj, sf::Font font, std::string text, sf::Color color, int size, int positionX, int positionY) { obj.setCharacterSize(size); obj.setFont(font); obj.setColor(color); obj.setString(text); obj.setPosition(positionX,positionY); } Using:

SFML tilemap collision

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:57:50
问题 I'm making a 2D game in SFML and I'm trying to figure out how to collide with tiles in a tilemap. I've written some code but the problem is that I get stuck in the tile I'm colliding with as you can see in the picture below. I cannot move in any direction and around 5 pixels of the player is in the wall. This is my collision / movement code void Player::update(float delta, std::vector<Tile>& tiles) { canMove = true; for (int i = 0; i < tiles.size(); i++) { if (Collision::PixelPerfectTest

How to adjust a game loop frame rate?

我们两清 提交于 2019-12-11 02:53:49
问题 I'm at the moment trying to Programm my first Game in SFML (and my first overall) but i ran into the Problem that i get a stutter about once a second. During such a stutter the Frametime is 3 to 4 times higher than normal which is really noticeable as long i don't run really high FPS (300+). No Problem (at least atm) as performance is not an Issue, but: When doing that my movement Method really freaks out and moves way way slower that it's supposed to do. my Movement method: void Player: