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

Pages: [1]
1
Graphics / Re: Get Image of rotated sprite
« on: June 17, 2017, 02:27:53 pm »
Finally I was able to solve the last piece of the puzzle. I had to add these lines to tell the render texture where should it draw the sprite:

sf::View view(a.getGlobalBounds());
renderTexture.setView(view);

Now instead of drawing the sprite from coordinates 0, 0 it is drawn from the coordinates where the sprite is located. My pixel perfect collision detection is now working and next it is time for optimisation. Thanks for all the help and especially AFS who helped me to get to the right track to solve this problem.

If someone is reading this topic to solve a problem similar to mine I must say that the code presented in the topic has changed quite a bit from the beginning and is not valid anymore. However, I can help. Just leave a reply to the topic.

2
Graphics / Re: Get Image of rotated sprite
« on: June 16, 2017, 07:32:44 pm »
I was able to solve the missing pixels problem. First, I made a little change how I draw the sprite to the window. I now create new sprite from the render texture and then draw the created sprite to window like this:

sf::Sprite c(renderTexture.getTexture());
window.draw(c);

Earlier it was like this:

window.draw(a);

where I drew the original sprite to the window.

After the change I noticed the whole sprite was not drawn to the window or it was but there was nothing to show. Empty pixels were drawn to the window.

After some tests I was able to find out that when I draw sprite to render texture it is not drawn according to the dimension of the sprite but according to the dimension of the window. I tested it by changing the size of the render texture to 600x600 and now I can see the rectangle drawn to the window. I added a screenshot to demonstrate this.

To fix this I should control how the sprite is drawn to the render texture. What part is drawn but all I can do is to control the size of the render texture and the position of the sprite. I can't control which part of the sprite is drawn to the render texture or maybe I could somehow I just don't know how. Another way to solve the problem would be to create a render texture size of the window and only loop the part of the image the rectangle of the sprite is in but that would not be effective way because I should always create a new image size of the window.

3
Graphics / Re: Get Image of rotated sprite
« on: June 16, 2017, 01:02:14 pm »
Sorry,

img is the image of the render texture and the sprite is the original sprite "a". Names are different because the code is inside another method.

Here is how I create the image:

renderTexture.getTexture().copyToImage() and pass it to the method for printing. The Sprite a I pass there like it is.

Anyway, I just noticed that this line:
renderTexture.clear(sf::Color(0, 0, 0, 0));
clears the whole texture with alpha value 0. I tried to change it to:
renderTexture.clear(sf::Color::Blue);.

So it seems that clear is just filling the texture and doesn't really care about alpha values of the sprite. I'm not sure why I still got some strange differing values at the edges of the image.

Edit: The strange values at the edges of the sprite obviously are out of bounds of the image because the rotated rectangle width and height have some decimals. I should round down the width and height when looping through the pixels. Anyway, I still got the problem with alpha values.

New Edit: This call should draw the rectangle into the texture but it doesn't seem to be happening:
renderTexture.draw(a);
So everything was correct in the first place when I cleared the texture with transparent. But for some reason nothing is drawn to the texture or at least it looks like that when looping through the pixels.

4
Graphics / Re: Get Image of rotated sprite
« on: June 16, 2017, 12:33:42 pm »
Hello, it's been a while since I have had time to work on this problem. Such a big delay but here I go again and I'm still struggling with this problem. Something fundamental is still wrong and I got something to show now. Here I am trying to print each of the pixels of my rectangle:

// Here "a" is the sprite
sf::RenderTexture renderTexture;
renderTexture.create(a.getGlobalBounds().width, a.getGlobalBounds().height);
renderTexture.clear(sf::Color(0, 0, 0, 0));
renderTexture.draw(a);
renderTexture.display();

// Then I pass the sprite and the image of the renderTexture to a method inside another class...
// I stripped the method to show only important stuff

sf::Rect<float> rect = sprite.getGlobalBounds();
unsigned rprint = 0;

for (int i = 0; i < rect.width; i++) {
    for (int j = 0; j < rect.height; j++) {
        // If alpha value of the pixel is greater than 0 print 1 else print 0
        rprint = unsigned(img.getPixel(i, j).a) > 0 ? 1 : 0;

        // a boolean that is true only if P was pressed just to avoid prints no needed
        if (doprint) {
            std::cout << rprint << std::ends;
        }
    }

    std::cout << "" << std::endl;
}

And here is what I get from the print if the rectangle (100x100) is rotated (the rotated size was about 138x138):

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010

As you can see only some of the pixels at the edges of the rectangle seems to be holding alpha value greater than 0 which should be impossible. What's wrong?

5
Graphics / Re: Get Image of rotated sprite
« on: May 16, 2017, 06:29:38 pm »
"No pixel" is not a thing. Every pixel in SFMK is represented as RGBA. Notice the 'A' which represents the alpha value, i.e. transparency. Now any color can be transparent, be it black, white, green, yellow, as long as you set the alpha value to 255, you'll get a fully transparent color.

Thank you for the reply. Yes, I see. We are talking about alpha value here not rgb value. I was talking nonesense there with png images :)

I ran some more tests. It turned out that if I copy the image from RenderTexture I will get the transformed image. At least, the image size is the same as that of rectangle and I noticed that if I copied the image from my texture of the sprite the image size remained the original size (not including transformation). But still I got problems and I think it is because of this:
renderTexture.clear( sf::Color::White );
This seems to fill the entire texture with white color. Not just the rectangle inside the texture and that's why I get alpha value 255 from each of the pixels. I tried to change the color parameter to:
sf::Color(0, 0, 0, 0)
But then the whole rectangle is filled with color(0, 0, 0, 0) (transparent black). It doesn't seem to help if I draw the sprite to the texture after clearing it. So now I should somehow clear the rectangle and then draw the sprite to it so that it would include the pixels of the rectangle.

6
Graphics / Re: Get Image of rotated sprite
« on: May 16, 2017, 04:26:12 pm »
Hello,

thanks for the reply and sorry it took me so long. I have not had time to continue my project lately.

I tried your code but I ended up with the same result. I get the same color from each one of the pixels even though I rotate the image. In my case it is white 255.

I'm actually using png-images with transparent background. Does that mean the image doesn't hold any pixels for the transparent coordinates? In that case I could add some background color and mask it off. I know it's possible. I'm going to try it.

Edit: Actually, that can't be the case because it should not return value 255 then. Perhaps it should return value 0 because of reading a value from a coordinate that doesn't hold any pixel. I'm using the sprite height and width to go through the pixels. I have confirmed that the size of the sprite does change when rotating the sprite.

7
Graphics / Get Image of rotated sprite
« on: May 13, 2017, 09:53:21 pm »
Hi,

how to get rotated Image with rotated pixel map after rotating a sprite? It looks like if I rotate a sprite and then copy the image of the texture belonging to the sprite the pixels in the image are not correct. All the pixels return the color of the rectangle. It's like the image was just resized to fit the new rotated rectangle. But that can't really be the case? There must be some way how SFML draws the pixels to the screen. I just don't know how it's done.

Sprite sprite;
sprite.rotate(45);
Image img = sprite.getTexture()->copyToImage();

// loop through the image
// lets pretend that the sprite is at position (0, 0) here all the time
for (int i = 0; i < sprite.getGlobalBounds().width; i++) {
    for (int j = 0; j < sprite.getGlobalBounds().height; j++) {
        // all the pixels return the color of the rectangle
        std::cout << unsigned(img.getPixel(i, j).a); << std::endl;
    }
}

// I just quickly wrote this code here. There might be some errors but I hope you get the idea
 

I added an image as an attachment to demonstrate this. There areas A should not return the color value of the rectangle while the area B should return.

I bet there is some really simple thing I'm missing here.

8
Graphics / Re: Pixel perfect collision detection or is it needed?
« on: May 11, 2017, 02:04:36 pm »
Well, it's a long time since, but what I did when I needed pixel.perfect collision (for a lemmings like game)
Was:
1: spatial partitioning, terrain was decided in 32 by 32 boxes.
2: bounding box collision on anything shown in 1.
3: inner box collision (8 by 8 boxes inside the 32 by 32 boxes of the terrain)
4: pixel perfect collision on anything inside any 8 by 8 box that hit whatever I was testing against.

Why? Because testing 15 figures of 8 by 16 pixels and each weapon/tool effects texture against a map of > 1000 by 1000 pixels was simply to much.
This way it was just any 8 by 8 square close enough against a 8 by 16.
And that was still over 8000 tests...

Just some experience... That said... It was in Java and many years ago..

Thank you! This was really helpful and good ideas. It's simple and I like it. I was thinking of dividing the terrain in different sized squares depending on how the terrain is formed but now that I look at into your solution I can see it's just much simpler to divide the terrain in certain amount of squares and those squares in smaller inner squares. So I can use the same logic in every maps.

Quote
Again, in pixel-perfect, detecting a collision is not the hard part. What you do with it is the hard part.

It's true that it's surprisingly simple to implement. But taking into account that it's my first time really making any games these things can seem quite complicated to me first. And what was difficult was to optimize it in somehow. I know what you said about premature optimization but this is not really even optimization it's like making it sensible enough that you can run it somehow :).

This weekend I got some time and I'm going to implement my first version of collision detection. I'll get back to this next week.

9
Graphics / Re: Pixel perfect collision detection or is it needed?
« on: May 09, 2017, 01:57:46 pm »
Thanks for the reply!

That might work for most of the part. However, I was thinking of using similar environment to Worms games. So that means there will be lots of curvy shapes. As far as I know, SAT is not suitable for curvy shapes.

I was actually trying to explain what I've been thinking here but I found out that it's too difficult without using any demonstration images. Anyway, I was able to implement a semi-pixel-perfect collision detection test and by that I mean I can check if a sprite boundaries is colliding with a pixel of another sprite. So it is like one-way pixel perfect collision detection. I still have some problems and some ideas how to solve them but I'll get back into them after I've drawn some pictures to demonstrate the problems.

10
Graphics / Re: Pixel perfect collision detection or is it needed?
« on: May 08, 2017, 02:49:37 pm »
Hi,

premature optimization is the root of all evil? Good tip! :). But tbh, I really don't have much understanding how heavy task it will be so that's why I was asking for an opinion.

Anyway, thanks for the reply! SAT looks like good option and I'm definitely looking into it. Perhaps best would be to implement both Pixel Perfect and SAT and see how it goes. At least now I think convex polygons are enough for me and I don't need to have concave polygons. So maybe SAT could be better but I just can't figure out it all yet. At least now I have something to start with and I'll see how it goes.

Btw, I don't really understand what you mean by pixel-perfect collision resolution?

11
Graphics / Pixel perfect collision detection or is it needed?
« on: May 08, 2017, 12:38:02 pm »
Hello,

I found from wiki there is implementation for pixel perfect collision detection and I have heard from many sources I should try to avoid it. However, it really looks like I need it. At least in some parts.

I'm working on a cave flying game. My plan is to have different kind of space ships. Because of the nature of the game I think I can't avoid using pixel perfect collision detection. I should know when bullets and missiles hit the ships and also when ships are colliding with the environment. But before I start implementing it I would like to hear opinions about collision detection. So what's your opinion? Does anyone know a good solution for collision other than pixel perfect that could fit my requirements?

I was thinking of forming a ship using multiple rectangles but then I should implement the rectangles for each of the ships because they are different shape and even then it wouldn't be pixel perfect and I think it could really harm the gameplay. And how should I move the rectangles? Should I move and rotate them with the ship? I'm not sure it would work but I could give it a try. Then I could detect if the ship rectangle is colliding with anything and after that go through every inner rectangle and check if any of them collide.

It would be a lot easier if I could just use textures and let one universal implementation take care of the collision detection. If it is just possible and would not slow down the game too much. After all I would like the game run smoothly and be light-weight.

Thanks in advance!

12
Hello,

this morning I got my sample project working! :) I just deleted all the files that cmake does and run it again. Then I was able to install the project with make and run it. An empty black window opened without errors just like it was supposed to. If anyone wants to know how I built SFML in OSX without any IDE and setup a sample project can leave a reply to this topic and I can try to help you. It was quite tricky one and I needed to pick up clues from different sources and sum them all together to get it working.

13
Hi,

I've been trying to build SFML and setup a sample project without success. I'm running OSX and I want to use CMake to build the project and setup my sample project. I've been following the tutorial https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake. I finally was able to build and install my project but when I tried to run the program I got error libraries are missing.

I realised I hadn't built SFML but it seems Mac Version of SFML is missing CMake files to build it. I downloaded the version that should contain all the source files and I was able to build it but now when I try to rebuild and then make (make install) my project I get errors from missing library again. I think all the source files are not compatible with OSX probably or maybe something else is messed up.

I'm quite lost here. Could someone point me a step-by-step guide how to build SFML and setup a sample project using CMake?

Pages: [1]