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

Pages: 1 [2] 3 4 5
The position is changed with sf::Transformable::setPosition. The bounds are given by sf::VertexArray::getBounds(). How would these two things interact with each other without you doing something? How would you get a changing bounding rect magically without doing anything in your class?

sf::VertexArray::getBounds() simply returns the min/max of the vertices' coordinates. If you never change them, then the bounding rect will never change as well.

On the other hand, changing the position changes the translation components inside sf::Transformable, and in result, modifies the entity's transform (getTransform()).

Now... after correctly understanding all that stuff, how to write a getGlobalBounds() function that works similarly to SFML entities' getGlobalBounds()? Simply by transforming the vertex array bounds by the entity's transform. And taking the bounding rect of the result.
Very interesting! After reading your answer i tried "doing something" to changes the 4 variables defining the FloatRect obtained through getBounds(), so i did the following :

1) Store the FloatRect obtained with getbounds in 4 variables.
2) Each time the vertex moves, modify the first and second variables which were the initial "left" and "top" components of the floatRect. I never modify the "width" or "height" variables.
3) Use a FloatRect that contains the new "left" and "top" variables with the old width and height variables, and use it directly with "intesects".

So whenever my object moves, i get a FloatRect similar to the getGlobalBounds() i think? It seems to be working.

___ Now let's move to phase 2
Now to understand SFML better as you are suggesing me, maybe i should try to do it with "getTransform()) as you suggest.
To sum up, the transformable class (which my class derives from ) has the ability to use getTransform(), it generates an object from the class sf::Transform.
Its functions https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Transform.php
Seems to have very few "getters" (but probably good enough), i don't see a getter that would give me information that can be applied to the vertexArrayObject.getBounds() to change it... I am sure there is but i don't see it.
It's probably inside the "getMatrix () const" function? which gives a matrix of four variables. I am supposed to use these 4 variables and apply them to the FloatRect obtained with GetBound(), then use the resulting FloatRect, i think?

Happax showed me a link to understand the 3x3 matrix and it's effects, i guess i have to dig more, but yeah i used another method and left the getTransform methode you are telling me about unfortunately, i would like to be able to do the method you are describing.

I really think you're going too fast. You're trying complicated stuff (it is!) without having a solid background (you thought it was caused by the "const" keyword, which doesn't make any sense).

Can't you work with SFML entities directly, until you understand SFML better? Why do you create your own entity class? What are you trying to achieve, what's your final goal?
True, since i understood how to inherit from the Transformable class i felt i can do anything.. and tried to do anything. Yes i am moving too fast, that's becuase i feel i am being too slow  ;D.

So my goal (for now) is as follows :
--- I have a big map containg.. let's say.. houses, like this :

---Each house has a FloatRect.
---My vertixClass allows me to create any shape, the little object in the upper left is the shape (it's not exactly a triangle, it's a combinason of three VertixArray's).
I am using a vertexClass because i want it be able to expand the entity and make it smaller at will, and i want it to have a specific shape, convex and concave. That's why i am not using the regular "shape" entities that SFML offers such as RectangularShape etc..

---What i want to do?
When my entity moves and reach a certain floatRect (which can be the green house or the red one or anything), something happens : a sound plays or the house is destroyed.

To test if the entity reached the house, you have to use the "intersects" function, and you have to obtain the entity bounds with getBounds (hence the beginning of this forum post).

So you can figure out the rest, i had a problem because getBounds did not give me a different FloatRect for each entity position, your solution  seems to be interesting which is to play with getTransform() and which i am not sure how to use, in the meantime i tried to "save" all the "movements" the entity does, if the item goes "right" i can predict if it has reached a floatRect.. something like that. And it did the trick somehow. Not sure if it's the best way to do it?
Thank you for your answers and time, by the way. It's great to have this forum.

How much time have you spend research each topic? ;)

I) I think there are tons of guides and articles on how to release a game on the play store.
II) There's obviously no silver bullet for advertising, otherwise everyone would just do that.
I always assume someone who has done it all, would love to share his experience.. something like that. But you are true i did not search a lot yet, i was just excited and tried and anticipate the informations. I will see when the time comes i guess.

It's like SFML, i enjoy using the "transformations" for vertices by inhereting the class transformation, it does all the math for me. It's kind of a shortcut. Why would i want shortcut with SFML and not want it with other things such as how to publish a game? ;D

Balance is key, i presume

Graphics / GetBounds Gives always the same results
« on: April 26, 2020, 01:20:17 pm »
Hello, i met with a problem : "GetBounds Gives always the same results"

My first SFML tutorial was the making of Pong game. It used the "getGlobalBounds" from the Shape class, and "intersects" from the Rect class. The ball AND the pad from the PONG game Were moving .. So the result of the intrescetion was sometimes "1" sometimes "0".

Fast forward to the example of this forum post, i have a VertexArray and i am using the "getBounds()" function. The problem simplly IS : "When The vertex shape MOVES, its bounds "getbounds values" are not changing. "

I thought maybe it was because the Getbound function was a "const", i redeclared it inside the vertexClass as a function without "const", and it did not change the result : getbounds gives the same results whichever is the position of the vertex shape.

Let's take an example, here is the class and its 2 functions (the  : "Contruction4noTex()" and "getBounds()" :
class VertexFun :   public sf::Transformable , public sf::Drawable
   private: /// ///////////////////////////////////////////
       sf::VertexArray V;
       sf::Texture Tex;
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const    {
        states.transform *= getTransform();
        states.texture = &Tex;
        //states.texture = nullptr;
        target.draw(V, states);
bool Contruction4noTex(sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2,sf::Vector2f v3,sf::Color c0, sf::Color c1,sf::Color c2,sf::Color c3)

              sf::Vertex* quad = &V[0];

                quad[0].position = v0;
                quad[1].position = v1;
                quad[2].position = v2;
                quad[3].position = v3;
                quad[0].color = c0;
                quad[1].color  = c1;
                quad[2].color  = c2;
                quad[3].color  = c3;
        return true;
        sf::FloatRect getBounds() {return V.getBounds();}

Declaration of a vertex shape called "v1" inside the main :
VertexFun v1;
v1.move(sf::Vector2f(0,64)); // giving the shape its initial position

Testing the intersection of the shape called v1 and a FloatRect :

                /// Testing bounds
                sf::FloatRect Rect3(64,64,32,32);
                     float a1= v1.getBounds().left;
                     float a2= v1.getBounds().top;
                     float a3= v1.getBounds().width;
                     float a4= v1.getBounds().height;
                     float b1= Rect3.left;
                     float b2= Rect3.top;
                     float b3= Rect3.width;
                     float b4= Rect3.height;

                    cout << " v1 bounds : " << a1 << " "  << a2 << " "  <<a3 << " "  <<a4 << " - And v1 position is : " << v1.getPosition().x << " " << v1.getPosition().y << endl;
                    cout << " icon 0 bounds : " << b1 << " "  << b2 << " "  <<b3 << " "  <<b4 << endl;
                    bool c1 = v1.getBounds().intersects(Rect3);
                    cout << " intesection : " << c1 << endl;

As you can see i i tried to follow the values on the console using "std::cout" while watching the position of the shape while it is moving.

Here is what the console shows :

The intersection result is "0" but if i defined Rect3 as (0,0,32,32) the result would be "1" but that's not the problem, the problem is getbounds() gives always the same values despite v1 moving, what i am missing?

Public inheritance is not a solution here -- as you noticed, it brings more problems than solutions.

What's the problem with this?
class VertexClass
    sf::FloatRect getBounds() const {return m_geometry.getBounds();}

    sf::VertexArray m_geometry;

Perfect! Worked perfecetly fine. SFML is fun, but i don't know when to use "const" yet, i shall use sf variable more often.
Thank you

I don't know if this should be in the "window help" section or here, but the problem i am presensting here, started when i wanted to get the Bounding boxes of my entities.

I made a class using vertices and wanted to get the bounding boxes through the function "getBounds" by inhereting the class from the "VertexArray" class, like this :
class VertexClass :  public sf::VertexArray, public sf::Transformable , public sf::Drawable
     private: /// ///////////////////////////////////////////
       sf::VertexArray V;
       sf::Texture Tex;
       virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const    {
        states.transform *= getTransform();
        states.texture = &Tex;
        //states.texture = nullptr;
        target.draw(V, states);
     public:/// ////////////////////////////////////////////////////////////////////////////////////////////////
         bool VertexFunction(sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2 ) //(...,PrimitiveType type)

                V[0].position = v0;
                V[1].position = v1;
                V[2].position = v2;
                V[0].texCoords = v0;
                V[1].texCoords = v1;
                V[2].texCoords = v2;
        return true;

One problem when calling the "draw" function :
VertexClass VClass;


Error message is :
'sf::Drawable' is an ambiguous base of 'VertexClass'

I searched on the internet and found these solutions : https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbclx01/cplr138.htm

Maybe i did not get it but i tried the following options :
I tried then to modify the class declaration, and added "sf::Drawable" before the draw function declaration. Still have the problem..

1) So how do we solve this situation if anyone knows?
2) Is there a better method to get the bound box of my verticesClass? (This is way i choose to put the post in the graphics section of the forum).

The "next chapter" is the one about sf::Transform. This is a lower level class, more flexible than sf::Transformable, and thus it allows one origin for each transformation if you really need it.


Yes that's what i thought. Gotcha

General / Re: Free Textures/ images/ icons/ musics/ sounds /songs..
« on: April 20, 2020, 07:04:37 pm »
Yes i guess, it's just i thought i might get a complete list from some veteran who had already went through this steps.

SFML projects / Re: Bullet Hell Game
« on: April 20, 2020, 07:03:11 pm »
You should share some video so we can judge the music better.
Also, this forum has many "guests" know that your screen shots do not show only if a member is logged in, just for you information;)

You're mixing real-time input and events. Best to check "isKeyPressed" outside the event loop.

If you're using events, you can pair the KeyPressed event to the KeyReleased event.

But, if you're just using real-time input, you can do it like this:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
    u = 1;
    u = 0;

Or shorter:
u = (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) ? 1 : 0);

Oh much better, thank you Hapax :).

SFML projects / Re: My first coding program: Xenon
« on: April 20, 2020, 05:23:26 pm »
I like it,
Where did you get the "alien" and "alien ammo" images from? Did you make them?

General / Free Textures/ images/ icons/ musics/ sounds /songs..
« on: April 20, 2020, 05:12:10 pm »
Do you have a list of websites where you can get your hands on free Textures, or any kind of images (small for chars to big for backgrounds). Same thing for sounds or musics?

I mean, material you can you use freely in a game that would sell.. someday.

SFML projects / Re: Project Arcanus
« on: April 20, 2020, 05:03:18 pm »
Hi all, i'm new to both SFML and the forums here, but wanted to share something I am currently working on.
I've been a developer now for around ten years, but I mostly work in web. I wanted to get my feet wet with C++ and Game Development after a long hiatus from doing anything related to game dev and was shuffled along to SFML by recommendation and so far, I love it.

I wanted to create something that would be fun to me and taking inspriration from games like Terraria, I decided to begin development of this project a couple of days ago.

So far, I have this:

If it's hard to see you can go to the direct link here: https://sykestech-cdn.fra1.cdn.digitaloceanspaces.com/rendering.png

Basically I have some very simple terrain generation, it's built of chunks, at the moment 10x10 of 16x16 blocks. Each chunk is 100 blocks in size.  I can render infinitely if I wanted, but at the moment I just render 100,000 blocks. To keep the app from slowing down, I load chunks in and out when they come within viewable range of the camera. You can move left and right, albeit very choppily.

This is very much a work in progress and something i'll be developing over the coming year in my spare time. I've created a public github: https://github.com/sykestech/arcanus, so feel free to look at my code and tell me off for anything I am doing that isn't quite right or could be improved. Also feel free to contribute if you wish.

Again, just wanted to share what I have and looking forward to hearing your feedback.


Image link broken
Github link deleted.

So is there any SFML involved in the making?


I) Once your SFML C++ game is done, coded, compiled and ready to play by using the .exe file,

1) How far are you from being able to put it on the Google App Store?
A) I know you have to pay few bucks, like 100€/$ a year?
B) I think you have to use something called android studio? Wrong?
C) You have to make sure you have no copyrighted material ? (music/images..)
D) ..

2) Making it into a flash game, is possible? Or do you have to had coded it in other langages?

II) What is the best strategy to advertise for your game?
A) Present it to some videogame website and ask them for a review? Or Youtuber/blog
B) Ask for SFML forum memebrs for support
C) Sell it for some company making games that would advertise it and get like a 50% cut revenues?
D) put for free and rely on "ad revenues" ?

SFML projects / Re: Bullet Hell Game
« on: April 20, 2020, 04:46:28 pm »
Looks very fun, the player is the black square?

Pages: 1 [2] 3 4 5