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

Pages: [1]
1
General / Re: Get the Screen Location of a VertexArray
« on: April 30, 2021, 10:59:00 pm »
Rather than use sf::Transform directly you might want to try inheriting sf::Transformable

I've setup my Asteroid class now like this:

class Asteroid : public sf::Transformable
{...

Now I can call every function that derives from sf::Transformable but when I call getPosition() I only get the value "0" (for both axis).





Edit: Also I (think I) have to return sf::Transform of my VertexArray in the window.draw() function:

window.draw(Asteroid.getShape(), Asteroid.getTransform());

...because otherwise the class is always located at Screen position 0,0 (upper left corner).

Besides I should also mention that this class is about to have a collision (a topic I haven't touched yet) and maybe should rotate too. I guess this is important to know as it'll probably have an impact on how the class is created.

2
General / Get the Screen Location of a VertexArray
« on: April 30, 2021, 12:19:50 pm »
Hi!
I'm currently working on a Asteroids Project and got stuck with my Asteroid class which is created with a VertexArray.

The Problem that I'm facing is that I don't know how to get the current Screen Location of the Asteroid class. The Class is moving across the Screen so I need the position to keep track when the Asteroid is about to leave the visible area (Screen borders). It should appear at the opposite side of the Screen again.

(Btw: When I'm talking about the Screen I mean the window which I have created via sf::RenderWindow. I still figuring out the correct terminology so I apologize for being misleading.)


My PlayerShip class works like this when it's about to leave the Screen:

if (PlayerShip.getPosition().x > Screen.x) {
                                        PlayerShip.setPositionX(0);
                                }
                                else if (PlayerShip.getPosition().x < 0) {
                                        PlayerShip.setPositionX(Screen.x);
                                }
                                else if (PlayerShip.getPosition().y > Screen.y) {
                                        PlayerShip.setPositionY(0);
                                }
                                else if (PlayerShip.getPosition().y < 0) {
                                        PlayerShip.setPositionY(Screen.y);
                                }



I don't understand how I can “get” the Position of my VertexArray to create the same logic.

After a long time of research I came across advices to not draw directly on the sf::RenderWindow class. So I created a sf::View class but experimenting with it didn't solve my Problem.
Also I tried functions like mapPixelToCoords or mapCoordsToPixel but they didn't help me.

The only way of how I keep track of the Asteroid class position is when initializing the class with two arguments:

Asteroid::Asteroid(float startX, float startY)
{

        StartPosition.x = startX;
        StartPosition.y = startY;

        sf::Transform TransformAsteroid.translate(StartPosition);
}

...but this doesn't help me either. The StartPosition is of course always the StartPosition.


I have the feeling that I get something fundamentally wrong about the coordinate system and how I can work with a sf::Transform class and it's translate() function the same way that I can with a sf::Shape class (which my PlayerShip class is derived from).

Pages: [1]
anything