Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw Missing!?  (Read 35871 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Draw Missing!?
« Reply #15 on: August 07, 2008, 03:40:39 am »
Your code is correct. Maybe the current working path is not the one you think it is.
Laurent Gomila - SFML developer

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #16 on: August 07, 2008, 05:55:01 am »
i fixed it! oddly, the jpg file wouldnt load but converting it to a png solved the problem

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #17 on: August 09, 2008, 06:15:07 am »
*bump for update email

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #18 on: August 10, 2008, 12:51:21 am »
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change

also, i switched to using arrays, so i have sf::Image other[5] instead of sf::Image Opening and such, but the image does not load for some reason...it did before

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #19 on: August 10, 2008, 01:49:39 am »
heres my code, i cant seem to find why it wont work plz check for errors due to misused/wrong syntax

Code: [Select]
#include "SFML/Quickstart.h"
#include "SFML/String Conversion.h"

int width;
int height;
int IW;
int IH;
int begin;
int finish;

std::string base = "C:/Jeopardy/";
std::string end = ".png";

sf::Sprite Categories[6];
sf::Sprite Money[5];
sf::Sprite Opening;
sf::Sprite Questions[30];
sf::Sprite Answers[30];

sf::Image categories[6];
sf::Image money[5];
sf::Image questions[30];
sf::Image answers[30];
sf::Image opening;
sf::Music OpeningMusic;
sf::Music FinalJeopardyMusic;

void GetDesktopMode()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
width = DesktopMode.Width;
height = DesktopMode.Height;
}

int LoadImages()
{
for(begin = 0, finish = 5; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Slide" + middle + end;
if (!categories[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 4; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Money" + middle + end;
if (!money[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 29; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Questions" + middle + end;
if (!questions[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

for(begin = 0, finish = 29; begin < finish; begin++)
{
std::string middle = Convert(begin);
std::string image = base + "Categories/Answers" + middle + end;
if (!answers[begin].LoadFromFile(image))
return EXIT_FAILURE;
};

if (!opening.LoadFromFile("C:/Jeopardy/Other/Opening.png"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}


void LoadSprites()
{
for (begin = 0, finish = 5; begin < finish; begin++)
Categories[begin] = sf::Sprite(categories[begin]);

for (begin = 0, finish = 4; begin < finish; begin++)
Money[begin] = sf::Sprite(money[begin]);

Opening.SetImage(opening);

for (begin = 0, finish = 29; begin < finish; begin++)
Questions[begin] = sf::Sprite(questions[begin]);

for (begin = 0, finish = 29; begin < finish; begin++)
Answers[begin] = sf::Sprite(answers[begin]);
}

void ScaleSprites()
{
for (begin = 0, finish = 5; begin < finish; begin++)
{
IW = categories[begin].GetWidth();
IH = categories[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Categories[begin].Scale(IW, IH);
};

for (begin = 0, finish = 4; begin < finish; begin++)
{
IW = money[begin].GetWidth();
IH = money[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Money[begin].Scale(IW, IH);
};

for (begin = 0, finish = 29; begin < finish; begin++)
{
IW = questions[begin].GetWidth();
IH = questions[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Questions[begin].Scale(IW, IH);
};

for (begin = 0, finish = 29; begin < finish; begin++)
{
IW = answers[begin].GetWidth();
IH = answers[begin].GetHeight();
IW = ((width/6) * IW);
IH = ((height/6) * IH);
Answers[begin].Scale(IW, IH);
};
}

int LoadMusic()
{
if (!OpeningMusic.OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return EXIT_FAILURE;

if (!FinalJeopardyMusic.OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return EXIT_FAILURE;

return EXIT_SUCCESS;
}

int Load()
{
GetDesktopMode();
LoadImages();
LoadSprites();
LoadMusic();
ScaleSprites();
OpeningMusic.Play();

return EXIT_SUCCESS;
}



Code: [Select]
#include "Jeopardy.h"

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Jeopardy!");
Load();


while(App.IsOpened())
    {
sf::Event Event;
while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
};

App.Clear();

App.Draw(Opening);

App.Display();
    };

return EXIT_SUCCESS;
}

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #20 on: August 10, 2008, 05:26:42 am »
Quote from: "qsik"
heres my code, i cant seem to find why it wont work plz check for errors due to misused/wrong syntax


You need to tell us exactly what's not working as expected and post just the relevant code.  You can't post your entire app, ask "why doesn't it work?" and expect meaningful help.  You need to help us help you.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #21 on: August 10, 2008, 05:29:25 am »
Quote from: "qsik"
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change

also, i switched to using arrays, so i have sf::Image other[5] instead of sf::Image Opening and such, but the image does not load for some reason...it did before


Getting the working directory is OS-specific.  You will need to google "get working directory c++ <OS name>."
As for arrays of images, that should work fine.  You probably have a problem somewhere else.  Are you sure you are indexing them correctly?

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Draw Missing!?
« Reply #22 on: August 10, 2008, 10:18:58 am »
Quote from: "qsik"
how would i get the path of where the exe is? that way i can load images and music even if the name of the folders change


if you have a folder structure like this:
Code: [Select]

game_folder
| - exe
| - data_folder
     | - img.png

you could in your code write img.LoadFromFile("data_folder/img.png");

This will work on most operating systems(at least windows, linux and mac OS) and is how most people do it :)
//Zzzarka

zac

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #23 on: August 10, 2008, 03:50:58 pm »
Getting the working dir in Windows uses the function "GetCurrentDirectory". The description of this function will be at msdn.microsoft.com .
In Linux, you have to usw getcwd() (take google/view die-linux manpages)...
by the way, you could use relative paths...

To get the real directory of your executable file in Windows, you use first:
GetCurrentProcess() to a call to GetModuleFileNameEx.
Again, both functions are described at msdn.microsoft.com .

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #24 on: August 10, 2008, 05:23:01 pm »
using the SVN version of SFML with VC 2008, i cant get my images to load (checking the image variables when debugging shows them to be empty :( )
i posted my code to see if anyone could find anything wrong with the code (as in incorrect syntax)

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Draw Missing!?
« Reply #25 on: August 10, 2008, 06:06:06 pm »
I'd suggest that you should use relative path names, get the working directory or use some sort of system variable instead of using hardcoded pathnames...seriously!!!
Is there any error output (like "can't fopen")?
Maybe your "Convert" function produces a  unwanted result.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #26 on: August 10, 2008, 06:48:09 pm »
yes, but the Opening sprite does not appear even though it does it has a hardcoded path, my question is why it wont appear

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #27 on: August 11, 2008, 02:35:31 am »
u were right, the for loops in my LoadImages(); was causing my sf::Image Opening to not load...odd

for images, are vectors better than arrays?

otherwise, im not sure how to mass load images in succession, ex. my program looks through subfolders for images labled Slide1, Slide2, ... and so forth

how would i go about achieving this effect? i tried converting ints to string as in my current program but it doesnt seem to work

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #28 on: August 11, 2008, 03:10:51 am »
Quote from: "qsik"
u were right, the for loops in my LoadImages(); was causing my sf::Image Opening to not load...odd

for images, are vectors better than arrays?

otherwise, im not sure how to mass load images in succession, ex. my program looks through subfolders for images labled Slide1, Slide2, ... and so forth

how would i go about achieving this effect? i tried converting ints to string as in my current program but it doesnt seem to work


There should be nothing wrong with using arrays (or vectors) or images.  Step through your code in the debugger, checking the variables along the way to find where it's doing something you don't expect.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #29 on: August 11, 2008, 05:42:17 am »
i fixed my image code, but i still cant get GetModuleFileName to work, how do i use it so i can get a string to use? if i use strings, i get errors but i dont know how to turn TCHARS into strings!

 

anything