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