1
Graphics / Error with calling sf::Sprite
« on: December 18, 2011, 10:17:08 pm »
Thank you so much for the help!
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.
Title = new sf::Sprite(ITitle);
Errors:
no matching function for call to 'sf::Sprite::Sprite(sf::Image*&)
int LoadMedia();
int Menu(sf::Sprite*, sf::Sprite*, sf::Sprite*, bool, sf::Music*);
int Game(sf::String*, sf::Music*, sf::Sprite*, sf::Sprite*, sf::Sprite*, sf::Sprite*);
int main() {
LoadMedia();
Menu(Title, Easy, Hard, MouseLeftDown, MenuMusic);
Game(HealthText, GameMusic, playerSprite, World1, World2, spacestationSprite);
}
int LoadMedia () {
//Picture Data --------------------------------------------------
sf::Image ITitle;
if(!ITitle.LoadFromFile("media/images/UI/title.png")) {return EXIT_FAILURE;}
sf::Sprite Title(ITitle);
Title.SetCenter(221,51.5);
sf::Image difficultyImage;
if(!difficultyImage.LoadFromFile("media/images/UI/difficulty.png")) {return EXIT_FAILURE;}
sf::Sprite Easy(difficultyImage); //Easy
Easy.SetSubRect(sf::IntRect(0,0,200,50));
Easy.SetCenter(100,25);
sf::Sprite Hard(difficultyImage); //Hard
Hard.SetSubRect(sf::IntRect(0,100,200,150));
Hard.SetCenter(100,25);
//Music Data -----------------------------------------------------------------
sf::Music MenuMusic;
if(!MenuMusic.OpenFromFile("media/music/The Son of Flynn.ogg")) {return EXIT_FAILURE;}
sf::Music GameMusic;
if(!GameMusic.OpenFromFile("media/music/Separate Ways.ogg")) {return EXIT_FAILURE;}
// Text Data -----------------------------------------------------------------
sf::Font MyFont;
if (!MyFont.LoadFromFile("media/Bedizen.ttf", 25)) {return EXIT_FAILURE;}
sf::String HealthText;
HealthText.SetFont(MyFont);
HealthText.SetColor(sf::Color::Black);
HealthText.SetSize(20);
}
int Menu (sf::Sprite* Title, sf::Sprite* Easy, sf::Sprite* Hard, bool MouseLeftDown, sf::Music* MenuMusic) {
(*MenuMusic).Play();
(*Title).SetPosition(Menu.GetWidth()/2,100);
(*Easy).SetPosition(Menu.GetWidth()/2,340);
(*Hard).SetPosition... yadda yadda yadda
Menu.Draw(*Title);
Menu.Draw(*Easy);
Menu.Draw(*Hard);
}
error: Title was not declared in this scope
int LoadMedia();
int Menu(sf::Sprite*);
int Game();
int LoadMedia() {
sf::Image ITitle;
if(!ITitle.LoadFromFile("media/images/UI/title.png")) {return EXIT_FAILURE;}
sf::Sprite Title(ITitle);
Title.SetCenter(221,51.5);
}
int Menu (sf::Sprite* Title) {
Title.SetPosition(Menu.GetWidth()/2,100);
}
int Game() {
//The usual stuff
}
int main() {
LoadMedia();
Menu(Title);
Game();
return EXIT_SUCCESS;
}
error: request for member 'SetPosition' in 'Title', which is of non-class type 'sf::Sprite*'
//In main.cpp
{
sf::Vector2f Center(5000, 5000);
sf::Vector2f HalfSize(512, 384);
sf::View View(Center, HalfSize);
sf::RenderWindow App;
App.Create(sf::VideoMode::GetDesktopMode(0), "Onyx [Alpha]", sf::Style::Fullscreen);
{
App.SetView(View);
if (App.GetInput().IsKeyDown(sf::Key::Add)) View.Zoom(1.1f);
if (App.GetInput().IsKeyDown(sf::Key::Subtract)) View.Zoom(0.9f);
View.SetCenter(pl.RenderPlayerX, pl.RenderPlayerY);
App.SetView(App.GetDefaultView()); //Sets View to be correct for drawing the HUD
App.Draw(SHealth);
App.Draw(STempTop);
App.Draw(HealthText);
App.Draw(EnergyText); //Draws the HUD
App.Draw(FuelText);
App.Draw(CurrencyText);
App.SetView(View);
App.Display();
}
return EXIT_SUCCESS;
}