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

Pages: [1]
1
General / Re: Collision detection with an image.
« on: April 02, 2015, 01:01:52 pm »
Ok I think i will try pixel perfect collision, and I'll change it up later down the line if I have performance issues. Thanks for your help! How do I do it using SFML?

2
General / Re: Collision detection with an image.
« on: April 01, 2015, 07:36:24 pm »
If you don't care AABB then the following should work for you. Otherwise just google for 'AABB collision detection' and you should find plenty of articles. By the way, I really doubt you will need pixel perfect collision.  ;)

if (player.getGlobalBounds().intersects(object.getGlobalBounds())
{
   // collision
}

http://www.sfml-dev.org/documentation/2.2/classsf_1_1Rect.php

I dont think you quite understand. I'm wondering how I can detect whether or not the player is within the white space of the picture. getGlobalBounds() simply deals with rectangles, which is not what I'm dealing with for my "spike" object.

3
General / Collision detection with an image.
« on: April 01, 2015, 06:13:29 pm »
I have a "spike" object which I want to implement into my game, which has:
  • A particular image, which looks something like this:
  • A position
  • And a rotation
The position and rotation can change dynamically.

I can get the thing to display, but I don't know how to do collision detection. I was thinking of either creating some sort of shape around the object upon initialization and somehow collision detect with that, or use pixel perfect collision.

However I don't know which one is better, or if there is another solution, and in any case I dont know how to achieve those things. I have only dealth with rectangles and circles when it comes to collision detection in the past.

Can someone give me a hand?

4
General / Re: Save to Image not working?
« on: March 22, 2015, 01:37:19 am »
You're forgetting sf::RenderTexture::clear() and sf::RenderTexture::display().

They're very similar to a sf::RenderWindow.

Actually I was forgetting sf::RenderTexture.create();  :)
clear and display are only for interacting with the screen, not saving an image

5
General / Save to Image not working?
« on: March 22, 2015, 01:07:56 am »
I have written the following code:


    string imageName = "levelImage";   
    sf::RenderTexture r;
    for(vector<GameObject*>::const_iterator i = gameObjects.begin(); i != gameObjects.end(); ++i) {
        (*i)->render(r);
    }
    r.getTexture().copyToImage().saveToFile(imageName);

Which should create an image of all my gameObjects. However, I am getting the error message: "failed to save image: "levelImage.png"" I am almost certain the problem is not within the for loop btw.

6
General / Re: Drawing onto PNG instead of onto window using SFML
« on: March 22, 2015, 12:56:30 am »
then get the sf::Texture of your render texture

How can I do this?

7
General / Re: Drawing onto PNG instead of onto window using SFML
« on: March 22, 2015, 12:00:17 am »
You can draw everything onto a transparent sf::RenderTexture, then get the sf::Texture of your render texture, then copyToImage() and saveToFile().

But if it is "a lot" larger than your window, you may be limited by the maximum texture size.
Ok, thanks a lot! I'll see what I can do, I haven't messed around with that yet. When I say a lot, I'm talking about 5000px maximum, so I think I'll be fine.

8
General / Drawing onto PNG instead of onto window using SFML
« on: March 21, 2015, 10:51:30 pm »
I am creating a platformer game using SFML, and my "Level Size" is a lot larger than my window size. So I am using sf::View to move around the view while I move.

What I do every frame is:
  • I draw everything onto the window
  • Set the view to be part of the window
  • Run window.display()
  • Run window.clear()
What I want to do now, however, is to draw each element onto an image (.png) file. A couple details:
  • This image should be the same size as my "Level Size"
  • I don't want it zoomed in anyway - it should not be affected by my current window or view
  • Finally there are transparent parts of the image, because I have not drawn them onto my canvas. I do not want these black in my image, but rather transparent
How can I achieve this? Ideally I would like to run a function like this: exportPNG(string filename, level).
Thanks a lot!

9
General / SFML 2.2 Error involving glew (and maybe opengl)
« on: March 13, 2015, 12:03:03 am »
I recently upgraded to SFML 2.2, and after this my code stop running.
I get these error messages now, and I am assuming it is related to glew (and maybe opengl)
(click to show/hide)
Nothing else has changed since I updated

10
General / Re: Repeating a texture when using a tileset
« on: March 04, 2015, 07:18:37 pm »
When using a sprite atlas as shown, do yourself a favor and look at sf::VertexArray. It's just the best solution to your problem and scales in the long run performance-wise.
I know that for sure, as I just conquered the same "problem" ;)

Ok I will! Thanks a lot for your input, there's a chance you've saved me a lot of headache later!

11
General / Re: Repeating a texture when using a tileset
« on: March 04, 2015, 08:59:53 am »
No.

Ok thanks a lot for your help :)
It seems the best way to do it for now is just to add a "repeating" boolean to my draw function, and then draw the sprite multiple times. Thanks for your input.

12
General / Re: Repeating a texture when using a tileset
« on: March 04, 2015, 08:56:33 am »
Quote
Is there no simpler solution?
Nop.

Can one sprite support multiple textures in it at once?

13
General / Re: Repeating a texture when using a tileset
« on: March 03, 2015, 11:35:57 pm »
How about just drawing your sprite repeatedly at all the positions where you want it?
Yes, that's a lot of draw calls and not the "optimal" solution, but usually it is "good enough" performance wise.
Or you could use a sf::VertexArray - see also the tutorial entry.

Is there no simpler solution? I have a "draw" function which takes a sprite and a position, and I would be great if the texture was looped for the sprite object itself.

14
General / Repeating a texture when using a tileset
« on: March 03, 2015, 11:15:38 pm »
For my basic "obstacle" object, I have sprites which have a width and height which is larger than those of the textures they are using. In order fix this, I use texture.setRepeated(true). However I want to use a tileset such as this one when I have multiple textures, using the sprite.setTextureRect() function in order to select the right texture. At this point, I can no longer have a repeating texture. How can I fix this issue, such that I can having a repeating texture for a sprite, whilst using a tileset and the setTextureRect() function SFML provides?

Pages: [1]