The rotated view is active at this moment and it seams that my sprite will go to the correct position but with a offset.
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
sf::RenderWindow window;
sf::RenderTexture _RenderTexture;
sf::RenderTexture SecRender;
sf::RectangleShape _BACKG;
sf::Event event;
sf::Mouse _Mouse;
sf::Sprite _Image;
sf::Sprite SecImage;
sf::View View;
sf::View StdView;
sf::Texture Wall;
sf::Sprite SWall;
void CreatField();
void DrawField(sf::RenderTexture &render, sf::RenderWindow &window);
void Input();
vector<sf::RectangleShape> Fields;
int main()
{
Wall.loadFromFile("Images/muster.png");
SWall.setTexture(Wall);
//SWall.setRotation(45);
_BACKG.setFillColor(sf::Color(0,0,0,0));
_BACKG.setSize(sf::Vector2f(1280,800));
View.setSize(1280,800);
View.setRotation(45);
window.create(sf::VideoMode(1280, 800 ,32), "Mengo", sf::Style::Default);
window.setKeyRepeatEnabled(true);
window.setFramerateLimit(30);
_RenderTexture.create(1280,800, true);
_RenderTexture.setSmooth(true);
SecRender.create(1280,800,true);
SecRender.setSmooth(true);
_Image.setTexture(_RenderTexture.getTexture());
SecImage.setTexture(SecRender.getTexture());
CreatField();
while(window.isOpen())
{
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
window.close();
default: break;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
window.clear(sf::Color(sf::Color(0,0,0,0)));
_RenderTexture.clear(sf::Color(0,0,0,0));
_RenderTexture.display();
SecRender.clear(sf::Color(0,0,0,0));
SecRender.display();
window.setView(StdView);///Standard View
window.draw(_BACKG);
window.setView(View);///Rotated View
DrawField(_RenderTexture, window);
SecRender.draw(SWall);
Input();
window.draw(_Image);
window.setView(StdView);///Standard View
window.draw(SecImage);
window.display();
}
return 0;
}
void Input()
{
///Moving the view
}
void DrawField(sf::RenderTexture &render, sf::RenderWindow &window)
{
for(unsigned int i = 0; i < Fields.size(); i++)
{
render.draw(Fields[i]);
if(window.mapPixelToCoords(sf::Mouse::getPosition(window)).x > Fields[i].getPosition().x && window.mapPixelToCoords(sf::Mouse::getPosition(window)).x < Fields[i].getPosition().x + 80.f &&
window.mapPixelToCoords(sf::Mouse::getPosition(window)).y > Fields[i].getPosition().y && window.mapPixelToCoords(sf::Mouse::getPosition(window)).y < Fields[i].getPosition().y + 80.f)
{
Fields[i].setFillColor(sf::Color::Cyan);
///HERE I SET THE POSITION FOR THE STANDARD VIEW
SWall.setPosition(static_cast<sf::Vector2f>(window.mapCoordsToPixel(Fields[i].getPosition())));
}
else
Fields[i].setFillColor(sf::Color::White);
}
}
void CreatField()
{
///Create the field
}
Maybe you can see the error?
Please remember, its just a experiment, so please don't rate the code.