1
Graphics / sf::Sprite Rotation causes Crash
« on: May 06, 2011, 03:15:48 pm »
Thanks at all, Pointers a still pretty new to me since i switched over from C#, so i'm glad you gave my some tips
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.
#include <SFML/Graphics.hpp>
int main()
{
RenderWindow window(...);
Image img = General::LoadIMG("myIMG.png");
Sprite spr(img);
//Main Loop
window.Clear(...);
window.Draw(spr);
window.Display(...);
return 0;
}
#include <SFML/Graphics.hpp>
int main()
{
RenderWindow window(...);
Image img = General::LoadIMG("myIMG.png");
Sprite spr(img);
spr.Rotate(0.5f); //Rotate the sprite.
//Main Loop
window.Clear(...);
window.Draw(spr);
window.Display(...);
return 0;
}
sf::Image General::LoadIMG(Cpt _file)
{
sf::Image img;
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
#include <SFML/Graphics.hpp>
#include <iostream>
#define lend std::endl
using namespace sf;
Image LoadIMG(char *_file)
{
Image img;
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
int main()
{
RenderWindow window(VideoMode(1280, 640, 32), "Caption goes here");
Event event;
Image img = LoadIMG("myIMG.png");
Sprite spr(img);
spr.Rotate(0.5f); //!Runs without this line and crashes with!
while(window.IsOpened())
{
while(window.GetEvent(event))
{
switch(event.Type)
{
case event.Closed:
window.Close();
break;
}
}
window.Clear();
window.Draw(spr);
window.Display();
}
return 0;
}
int main() {
Sprite spr;
spr.Rotate(0.5f);
return 0; }
Image img = General::LoadIMG(file);
Sprite spr = Sprite(img);
// by
Image img;
img.LoadFromFile(file);
Sprite spr = Sprite(img);
//Cpt = typedef char*
sf::Image General::LoadIMG(Cpt _file)
{
sf::Image img;
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
//Function for loading an image from file.
sf::Image General::LoadIMG(Cpt _file)
{
sf::Image img = sf::Image();
if(!img.LoadFromFile(_file))
std::cout << lend;
delete _file;
return img;
}
int main()
{
RenderWindow window(
VideoMode(1280,640,32),
"SFML 1.6 in Qt Creator",
Style::Close, WindowSettings(24,8,0));
Image img = General::LoadIMG("Arrow.png");
Sprite spr = Sprite(img);
}
window.Draw(spr);
window.Clear(...);
spr.Rotate(0.5f);
window.Draw(spr);
window.Display();