Bonjour,
je suis débutant en c++ et SFML 2.1, j'ai suivie le tuto sur OpenClassRoom(site du zero).
Bref je me suis dit que j'aller m'entraîne au 9SS, pour mon jeux. Alors j'ai écrit un petit bout de code mais voila sur les "sf::Sprite" il manque des pixel et sans raison la texture se répeter vers la fin.
Merci de 'avoir lue.
Voila un image du problème
Voila le code (en entier) 116 ln.
Désoler je ne met pas souvent de commentaire dans me test.
#include <SFML/Graphics.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>
sf::RenderWindow window;
sf::Vector2u ScreenSize(800,600);
void globalEvent()
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::Resized)
window.setSize(ScreenSize);
}
}
void Sprit(float Px, float Py, int Sx1, int Sy1, int Sx2, int Sy2, float scale, std::string path, sf::RenderWindow &windo)
{
sf::Texture text;
sf::Sprite rect;
text.setSmooth(false);
if(!text.loadFromFile(path))
std::cout<<"ERREUR "<<std::endl;
rect.setPosition(Px,Py);
rect.setTexture(text);
rect.setTextureRect(sf::IntRect(Sx1,Sy1,Sx2,Sy2));
rect.setScale(scale,scale);
windo.draw(rect);
}
void Window(float PosX, float PosY, int Sh, int Sw, float scale, int Size, std::string path, sf::RenderWindow &windo)
{
int H=0;
int W=0;
float Scale=0;
float PX=PosX;
float PY=PosY;
Scale=scale;
while(H!=Sw+1)
{
while(W!=Sh+1)
{
//Haut
if(H==0&&W==0)
Sprit(PX,PY,0,0,4,4,Scale,path,windo); //Gauche
if(H==0&&W>0&&W<Sw)
Sprit(PX,PY,5,0,9,4,Scale,path,windo);//Centre
if(H==0&&W==Sw)
Sprit(PX,PY,10,0,14,4,Scale,path,windo);//Droit
//Milieu
if(H>0&&H<Sh&&W==0)
Sprit(PX,PY,0,5,9,4,Scale,path,windo);//Gauche
if(H>0&&H<Sh&&W>0&&W<Sw)
Sprit(PX,PY,5,5,9,9,Scale,path,windo);//Centre
if(H>0&&H<Sh&&W==Sw)
Sprit(PX,PY,10,5,14,9,Scale,path,windo);//Droit
//Bas
if(H==Sh&&W==0)
Sprit(PX,PY,0,10,4,14,Scale,path,windo);//Gauche
if(H==Sh&&W>0&&W<Sw)
Sprit(PX,PY,5,10,9,14,Scale,path,windo);//Centre
if(H==Sh&&W==Sw)
Sprit(PX,PY,10,10,14,14,Scale,path,windo);//Droit
PX+=Size*Scale;
W++;
}
PY+=Size*Scale;
H++;
PX=PosX;
W=0;
}
H=0;
PY=PosY;
}
int main()
{
window.create(sf::VideoMode(ScreenSize.x, ScreenSize.y), "9-slice-scaling");
window.setFramerateLimit(30);
while (window.isOpen())
{
globalEvent();
window.clear(sf::Color::Blue);
Window(15,15,10,10,5,5,"C:\\Users\\User\\Desktop\\SuperRampageBrutal\\textures\\window.png",window);
window.display();
}
return 0;
}
Ps:je me demande souvent si mon code est assez propre au si ça fait trop le noob qui ecrit comme un sagoin.
Afficher la suite