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.


Topics - kingguru

Pages: [1]
1
Graphics / Collision detection between sprite and shape
« on: May 03, 2021, 08:56:47 pm »
I know collision detection is most likely a topic that has been brought up here quite often, so I'm sorry for bringing it up once again.

First of all, I am not very experienced with SFML, game development and 2D graphics in general so please bear with me.

I have written a very basic game using where balls (basically an sf::CircleShape) can hit a player (basically an sf::Sprite) and while using the intersects function works just fine I would of course prefer a bit more "pixel perfect collision detection".

Instead of reinventing the wheel I have found a few snippets like this one.

I've had to change the code slightly to use an sf::Shape for one of the objects, but I cannot really see how it should matter.

The problem is, that a collision very rarely happens and for small shapes, it seems like it doesn't happen at all.

My sf::CircleShape uses a texture that scales depending on the size and I have a suspicion that when comparing the pixels, the comparison happens using the full sized image/texture where only a corner of the original image is used which mostly only contains transparent pixels. As far as I've understood though, getInverseTransform should take care of that transformation right?

Hope my question makes some kind of sense. I am of course willing to share code and more details, but I'm a bit lost so I hope someone could give my some guidance from here.

Thanks a lot!


2
General / Failing to link release build on Windows
« on: March 27, 2021, 12:07:22 am »
I have a fairly simple SFML project that is also fairly simple in how I build it with CMake.

I use the standard CMake FindPackage command:

find_package(SFML 2.5 COMPONENTS graphics system window REQUIRED)

And then link it to my target:

target_link_libraries(${PROJECT_NAME} PRIVATE
  sfml-graphics
  sfml-system
  sfml-window
)

This work just fine on Linux with the SFML package installed from my package manager and on Windows it also works fine, but only when using the Debug configuration. Building it in release mode like this:

cmake --build . --config Release

Fails to link as there is no Release directory in the prebuilt SFML .zip file I downloaded (64-bit VS 2017). The Debug build works fine since there is indeed a Debug directory where I assume CMake tells the linker to find the required .lib files. As far as I can tell, both the Debug and Release version of the libraries are in the root lib folder of the prebuilt SFML .zip file.

Am I missing something? This seems like the "normal" way to build CMake projects on Windows, but I must admit I'm not very experienced on that platform.

Thanks a lot.

3
Graphics / Resize shape without scaling texture
« on: September 01, 2015, 10:03:33 pm »
Hi there,

Let's say I have a RectangleShape that I want to grow in height over time. In order to do that, in each call to my update() function I call setSize() with a new height and my shape grows nicely.

Now I have a texture that fills up the maximum size of my RectangleShape, but I only want to display parts of that texture as my rectangle grows. If I use setTextureRect() initially and set the maximum size of my RectangleShape, the texture will scale as the shape grows in height, which is expected but not exactly what I want.

I would really just like each resize of my shape to show more of the texture without scaling the texture.

I have tried to change the texture rectangle in each call to update by doing something like:

float height_increase = 2;
setSize({getSize().x, getSize().y + height_increase});
auto rect = getTextureRect();
rect.height += height_increase;
setTextureRect(rect);
 

With the initial size of the texture rectangle matching the initial size of my RectangleShape, but I couldn't really make it work and it also seems very "hackish" so I'm not really sure if this is the right way to go.

To make things slightly more complicated, I would really like to use the Animatior functionality from the very useful Thor library to animate my RectangleShape as it is growing in size, but that might not be that important to start with.

I can post a more complete example of what I'm trying to achieve if that makes it clearer, but I hope it's quite clear what I want to do and I feel like I'm approaching this the wrong way.

Any help or hints would be greatly appreciated as I'm fairly new to SFML and indeed to graphics/game programming in general.

Thanks a lot.

4
General / Prebuild binaries for Visual Studio 2015
« on: August 05, 2015, 08:48:32 pm »
Hi there,

Although I primarily work on Linux, I would like my code to work on Windows as well and therefore set up a small Windows installation with Windows 7 and the latest version of Microsofts C++ compiler.

The latest version of Visual Studio, as far as I can tell, is 2015 but there are no precompiled version of SFML available for download for that version yet.

I tried to compile SFML myself using the latest version of Visual Studio and faced some issues that I don't really want to bother you with since I'm fairly certain I could figure them out, but being lazy it would be nice not to have to do so that my question is simply:

Will there be a precompiled version of SFML for the latest version of Microsofts compiler available and if yes, then in which timeframe?

Additionally, it's been a while since I wanted to compile cross platform stuff on Windows so I'm not really up to date on what is currently the best way to do it. Should I just go with GCC (mingw?) or even clang instead?

Thanks a lot and hope this is the right forum to ask this in :-)

5
Graphics / Sharing sfml textures between class instances
« on: July 29, 2015, 08:27:32 pm »
Hi there,

I'm fairly new to SFML so please bear over with me if this has been answered a million times before. I just haven't been able to find a good example of this and it feels like there's something basic I'm not getting.

Let's say I have a class representing some sprite with a texture and I want to have more than one instance of that class and put that in an STL container. Something like:

class Ball
{
public:
  Ball()
  {
    texture_.loadFromFile("ball.png");
    sprite_.setTexture(texture_);
  }
private:
  sf::Texture texture_;
  sf::Sprite sprite_;
}

std::vector<Ball> balls = { Ball(), Ball() };
 

This is just example code that might not even compile to give an idea of what I'm trying to accomplish, but assuming it does this will still not work because you cannot (I think) copy an SFML texture which results in the "white square problem" I've seen mentioned often.

I have some different ideas on how to solve this, but they all feel sort of "wrong" which is why I feel like I am misunderstanding something.

You could:
  • Use a static shared_ptr, and then construct that the first time the class is initialized. This is sort of dirty and the fact that a sprite takes a reference to a texture hints that this is not the way to do it.
  • Using a global texture manager or similar which each instance can use to retrieve the texture. This has all the usual issues with global variables.
  • Creating the texture outside of the class using it and then giving every instance a reference to that. This is fairly cumbersome and I think it would be nicer to have the class using the texture owning it.

I've looked also looked at the ResourceManager from the Thor library, but that doesn't really seem to be useful for this case.

I know this is not that much a question specific to SFML, but I'm just really interested to hear how others are doing something like this since I cannot imagine I'm the only one facing this.

Thanks a lot.

Pages: [1]
anything