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

Pages: [1]
1
Graphics / Re: Collision detection between sprite and shape
« on: May 04, 2021, 11:00:09 pm »
Thanks a lot eXpl0it3r.

I know and understand that pixel perfect collision detection is rarely needed, it just kind of bothered me that I could clearly see that the player died even if an actual collision hadn't occurred. Could definitely be because I know that is the case though and not a real problem  :)

The game in question is a very basic attempt at reimplementing the class Pang! game that I started years ago and only recently had a look at again. The code is shared under the GPL here.

There are tons of known issues with the code and of course even more I don't know about, but it's mostly just a way for me to try and play with writing code in a field I'm not very experienced in, so please keep that in mind if you feel like you have the courage to read the code :)

The collision detection I wanted to improve is currently happening in the main function (it shouldn't be there, I know) and is simply using the intersects member function.

It is the indeed the same code from the SFML wiki I've tried using. I thought it would be more or less "drop in" which is why I'm a bit puzzled.

Considering the actual problem (improving collision detection a bit), I've thought about using some basic geometric calculation to figure out if the circle intersects with the (player) rectangle instead. Maybe that would be a better solution?

Thanks a lot once again. You're input is most appreciated.

2
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!


3
General / Re: Failing to link release build on Windows
« on: March 27, 2021, 08:42:51 pm »
@LucaCiucci

Thanks a lot for your reply.

I think I forgot the most useful information which is, that I was configuring CMake with:

cmake -DSFML_DIR="<path to SFML> <path to my CMakeLists.txt>"

Rereading the forum post where I originally found the instructions (https://en.sfml-dev.org/forums/index.php?topic=24070.0), that was clearly wrong as it states that I should set SFML_DIR to "<sfml root prefix>/lib/cmake/SFML".

Doing so works perfectly with both Debug and Release configurations.

So this was clearly just a mistake on my side, but thankfully I figured it out.

I generally don't think it should be necessary to mess around with environment variables for reasonably well written CMake projects, which SFML thankfully is. But if it works for you, then no reason to change anything of course :-)

Thanks once again. This can definitely be considered solved although I'm still wondering why it almost works when given the wrong path.

4
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.

5
Graphics / Re: Resize shape without scaling texture
« on: September 02, 2015, 08:25:16 am »
Hi Laurent,

Thanks for your quick reply.

It turned out the example I provided does indeed work as expected and my problems were related to position, origin and scaling when I resized the shape.

Note to future self and others: Adding a border to the shape you're having problems placing or sizing before using a texture makes debugging a lot easier  :)

But thanks a lot for confirming that this is indeed the right way to go, that's nice to know.

If someone would like me to post some example code, I can of course do that, otherwise this can be considered solved.

6
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.

7
General / Re: Prebuild binaries for Visual Studio 2015
« on: August 06, 2015, 09:50:05 pm »
Quote
What do you mean with "compile cross platform stuff"?

Sorry, bad wording.

I simply meant that it's been a while since I had to write C++ code that should compile and run on more than one platform, so I'm not sure what is currently the best ways to do that when it comes to choosing a compiler chain.

Thanks a lot for your work on the nightly builds. I'll look into to that.

8
General / Re: Prebuild binaries for Visual Studio 2015
« on: August 05, 2015, 09:10:12 pm »
Thanks Jesper.

It seems like the problem was me not being able to use the search function and only searched in a subforum instead of all of the forums.

There are indeed plenty of discussions related to this issue.

Sorry about that :-)

9
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 :-)

10
Graphics / Re: Sharing sfml textures between class instances
« on: July 30, 2015, 01:15:19 pm »
I solved it using the Thor Rersource classes and passing a reference around like Jesper suggested.

Works perfectly and the code is fairly clean. I could even get rid of my private texture member variable since I can construct the sprite directly by acquiring the texure from the resource manager in the constructor, so I actually ended up with less code  :D

Thanks a lot to both of you.

11
Graphics / Re: Sharing sfml textures between class instances
« on: July 29, 2015, 09:36:48 pm »
Thanks a lot for your answer Jesper.

I was actually thinking about the same solution, just didn't like the idea of having to pass a reference to every object I create if I could avoid it. That's definitely more a question of general code design than specific for SFML and not the first time I've had to deal with this when writing C++ code. :-)

I'm still interested if someone else have solved this some other way though. It's always interesting to hear different ways to solve a problem.

I will try to use the ResourceHolder from Thor. It seems to be doing exactly what your ResourceManager class is doing and since I'm already using Thor for some animation stuff I already have a dependency on that library.

Thanks once again.

12
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