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

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

0 Members and 1 Guest are viewing this topic.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #45 on: August 14, 2008, 06:50:21 am »
i switched to bmps cause the pngs werent working...but now the image sizes are much bigger :( (the pngs are exported from powerpoint slides --> a problem?)

--is there a way to get rid of sf::clock? i want to implement a timer so that SFML shows a "loading screen" while loading images in the background, but dont want the sf::clock to continually run and waste resources (im targetting older hardware so i need to save as much space as i can)

**still need help with GetModuleFileNameExW

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #46 on: August 14, 2008, 07:00:52 am »
Just open the pngs in GIMP and reexport them as pngs.  You don't need to save them as bmps.
I'm not sure what you mean by getting rid of sf::clock and then making your own timer.  sf::clock is very simple and you're not likely to make something faster.
And sf::clock doesn't do anything until you create an instance of the class and even then only when you call functions on it.  It's not really talking up resources at all.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #47 on: August 15, 2008, 10:19:07 pm »
im making progress, but a problem has popped up. i was using the debugger and my array for my "money" sprites has all the sprites loaded, their positions set, and the loop has the correct numbers to draw...but only the first row appears? here's my code, i cant seem to find the problem

Code: [Select]
for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};


Code: [Select]
void PositionSprites()
{
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;

for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};

for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}


Code: [Select]
for(int i = 0; i < 30; i++)
{
if(CheckMoney[i] == 1)
App.Draw(Money[i]);
};



qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #48 on: August 18, 2008, 05:31:43 am »
*bump

a little help?

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Draw Missing!?
« Reply #49 on: August 18, 2008, 11:57:51 am »
Your previous code:
Quote
sf::Sprite Money[5];


and then...
Quote
for(int i = 0; i < 30; i++)
{
   if(CheckMoney == 1)
      App.Draw(Money);
};


How can it work for i > 5 if the array size is 5 and the cycle has up to 30 iterations?

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #50 on: August 18, 2008, 07:41:28 pm »
sorry, i changed the size of Money[] to 30 to hold the needed 30 images unless there is a way to duplicate sprites w/o having to create more sprite variables

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #51 on: August 20, 2008, 04:32:38 pm »
*bump

--still cant figure it out

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Draw Missing!?
« Reply #52 on: August 20, 2008, 07:16:35 pm »
Post all your code (you probably made changes, right?) and I will try to go through it and fix it later today.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #53 on: August 20, 2008, 07:32:56 pm »
!!! WARNING !!! i dont use comments, but instead try to make my code make as much sense as possible through the use of good variable names and sensible function names though some of it may not make sense 'cause im not completely done

String Conversion.h

Code: [Select]
#include <iostream>
#include <sstream>
#include <string>

std::string Convert(int number)
{
std::stringstream converter;
converter << number;
return converter.str();
}


Jeopardy.h

Code: [Select]

#include "SFML/Quickstart.h"
#include "SFML/String Conversion.h"

int ScreenWidth;
int ScreenHeight;

int CheckCategories[6];
int CheckMoney[30];

std::string Path;

sf::Sprite Other[6];
sf::Sprite Categories[6];
sf::Sprite Money[30];
sf::Sprite Question;
sf::Sprite Answer;

sf::Image other[6];
sf::Image categories[6];
sf::Image money[5];
sf::Image question;
sf::Image answer;

sf::Music Music[4];

void GetDesktopMode()
{
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
ScreenWidth = DesktopMode.Width;
ScreenHeight = DesktopMode.Height;
}

std::string GetExeD()
{
GetModuleFileName(NULL, L"Path", 100);
return Path;
}

int LoadImages()
{
std::string base = "C:/Jeopardy/";
std::string end = ".bmp";
std::string middle;
std::string image;

for(int i = 0; i < 6; i++)
{
middle = Convert((i + 1));
image = base + "Other/Slide" + middle + end;
if (!other[i].LoadFromFile(image))
return -1;
image = base + "Categories/Slide" + middle + end;
if (!categories[i].LoadFromFile(image))
return -1;
};

for(int i = 0; i < 5; i++)
{
middle = Convert((i + 1));
image = base + "Money/Slide" + middle + end;
if (!money[i].LoadFromFile(image))
return -1;
};

return 1;
}

void LoadSprites()
{
for (int i = 0; i < 6; i++)
{
Other[i].SetImage(other[i]);
Categories[i].SetImage(categories[i]);
};

for (int i = 0; i < 5; i++)
{
Money[i].SetImage(money[i]);
Money[(i + 5)].SetImage(money[i]);
Money[(i + 10)].SetImage(money[i]);
Money[(i + 15)].SetImage(money[i]);
Money[(i + 20)].SetImage(money[i]);
Money[(i + 25)].SetImage(money[i]);
};
}

void ScaleSprites()
{
float ImageWidth;
float ImageHeight;

for (int i = 0; i < 6; i++)
{
ImageWidth = other[i].GetWidth();
ImageHeight = other[i].GetHeight();
ImageWidth = (ScreenWidth / ImageWidth);
ImageHeight = (ScreenHeight / ImageHeight);
Other[i].Scale(ImageWidth, ImageHeight);

ImageWidth = categories[i].GetWidth();
ImageHeight = categories[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Categories[i].Scale(ImageWidth, ImageHeight);
};

for (int i = 0; i < 30; i++)
{
ImageWidth = money[i].GetWidth();
ImageHeight = money[i].GetHeight();
ImageWidth = ((ScreenWidth/6) / ImageWidth);
ImageHeight = ((ScreenHeight/6) / ImageHeight);
Money[i].Scale(ImageWidth, ImageHeight);
};
}

void PositionSprites()
{
float xpos = (ScreenWidth/6);
float ypos = (ScreenHeight/6);
float x = 0;
float y = ypos;

for(int i = 0; i < 6; i++)
{
Categories[i].SetPosition(x, 0.0f);
x = x + xpos;
};

for(int i = 0; i < 5; i++)
{
Money[i].SetPosition(0, y);
Money[(i + 5)].SetPosition(xpos, y);
Money[(i + 10)].SetPosition((xpos * 2), y);
Money[(i + 15)].SetPosition((xpos * 3), y);
Money[(i + 20)].SetPosition((xpos * 4), y);
Money[(i + 25)].SetPosition((xpos * 5), y);
y = y + ypos;
};
}

int LoadMusic()
{
if (!Music[0].OpenFromFile("C:/Jeopardy/Music/Opening.wav"))
return -1;

if (!Music[1].OpenFromFile("C:/Jeopardy/Music/Question.wav"))
return -1;

if (!Music[2].OpenFromFile("C:/Jeopardy/Music/Daily Double.wav"))
return -1;

if (!Music[3].OpenFromFile("C:/Jeopardy/Music/Final Jeopardy.wav"))
return -1;

return 1;
}

void InitChecks()
{
for(int i = 0; i < 6; i++)
CheckCategories[i] = 1;
for(int i = 0; i < 30; i++)
CheckMoney[i] = 1;
}

int Load()
{
GetExeD();
GetDesktopMode();
LoadImages();
LoadSprites();
ScaleSprites();
PositionSprites();
LoadMusic();
InitChecks();
Music[0].Play();

return 1;
}


Main.cpp

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

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

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();
if ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left) && (stage < 3))
stage = stage + 1;
};

App.Clear(sf::Color(17, 86, 178));
if (stage == 1)
App.Draw(Other[0]);
if (stage == 2)
App.Draw(Other[1]);
if (stage == 3)
{
for(int i = 0; i < 6; i++)
{
if(CheckCategories[i] == 1)
App.Draw(Categories[i]);
};

for(int i = 0; i < 30; i++)
{
if(CheckMoney[i] == 1)
App.Draw(Money[i]);
};
};

App.Display();
    };

return EXIT_SUCCESS;
}

Avency

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Draw Missing!?
« Reply #54 on: August 20, 2008, 08:40:08 pm »
That part sure looks weird:
Code: [Select]
  for (int i = 0; i < 5; i++)
   {
      Money[i].SetImage(money[i]);
      Money[(i + 5)].SetImage(money[i]);
      Money[(i + 10)].SetImage(money[i]);
      Money[(i + 15)].SetImage(money[i]);
      Money[(i + 20)].SetImage(money[i]);
      Money[(i + 25)].SetImage(money[i]);
   };


You have 30 sprites but set only 5 images.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Draw Missing!?
« Reply #55 on: August 21, 2008, 01:46:04 am »
Perhaps you meant to do this...

Code: [Select]
sf::Sprite Money[31];


Code: [Select]
for (unsigned int x = 0; x < 5; ++x)
{
    for (unsigned int y = 0; y < 5; ++y)
    {
        Money[x + y].SetImage(money[x]);
    }
}


I couldn't compile your code to test this though.

NeWsOfTzzz

  • Newbie
  • *
  • Posts: 15
    • View Profile
Draw Missing!?
« Reply #56 on: August 21, 2008, 02:34:57 am »
@Wizzard: wrong, 2 errors :/

Correct version:
Code: [Select]
for (unsigned int x = 0; x < 5; ++x)
{
    for (unsigned int y = 0; y < 6; ++y)
    {
        Money[x + y * 5].SetImage(money[x]);
    }
}


And why?
Code: [Select]
sf::Sprite Money[31];
30 was enough!






@qsik, your problem is simple, you scale the sprites to zero
Code: [Select]
for (int i = 0; i < 30; i++)
   {
      ImageWidth = money[i].GetWidth();
      ImageHeight = money[i].GetHeight();
      ImageWidth = ((ScreenWidth/6) / ImageWidth);
      ImageHeight = ((ScreenHeight/6) / ImageHeight);
      Money[i].Scale(ImageWidth, ImageHeight);
   };


change to
Code: [Select]
  for (int i = 0; i < 30; i++)
   {
      ImageWidth = money[0].GetWidth();
      ImageHeight = money[0].GetHeight();
      ImageWidth = ((ScreenWidth/6) / ImageWidth);
      ImageHeight = ((ScreenHeight/6) / ImageHeight);
      Money[i].Scale(ImageWidth, ImageHeight);
   };


Your loop tries to access image[0] to image[29] but you only have image[0] to image[4].. Got it? ;)
.
.
.
.
.
.
.
.
.
.
.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #57 on: August 21, 2008, 04:59:42 am »
thnx man, it fixed the errors!

this is correct

Code: [Select]
for (int i = 0; i < 5; i++)
   {
      Money[i].SetImage(money[i]);
      Money[(i + 5)].SetImage(money[i]);
      Money[(i + 10)].SetImage(money[i]);
      Money[(i + 15)].SetImage(money[i]);
      Money[(i + 20)].SetImage(money[i]);
      Money[(i + 25)].SetImage(money[i]);
   };


making 30 images is too slow and costly, so creating 5 sprites of each money image is more efficient and loads quicker

as my small image in a previous post shows, the text in the images are kind of grainy. im scaling 960 x 720 images into (1024/6) x (768/6) images to fit all 36 images on the screen...why do they look kind of bad?

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Draw Missing!?
« Reply #58 on: August 21, 2008, 07:10:52 am »
You should be using comments anyway.  Any reasonably competent software engineer could look at the code and figure out what it does, but that's not the point.  Commenting paragraphs of code with a simple descriptor makes it much easier to read and maintain the code.
Good variable names and whitespace are important, but they're no substitute for coding.  Also, not commenting your code is a good way to get rapidly fired from a job since many employers don't want hard-to-maintain code in their system.  Better get used to it now.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Draw Missing!?
« Reply #59 on: August 21, 2008, 11:57:15 pm »
how descrptive should the comments be? could u give an example

 

anything