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

Author Topic: Drawing Everything  (Read 29802 times)

0 Members and 2 Guests are viewing this topic.

eleinvisible

  • Newbie
  • *
  • Posts: 47
    • View Profile
Drawing Everything
« Reply #30 on: May 21, 2008, 03:42:41 am »
I recommend at least copying and pasting the errors you get, and what lines it refers to, otherwise its like finding a (many) needles in a (very large) haystack.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #31 on: May 21, 2008, 08:26:55 am »
it works now yay :)

now how would i implement getting if the mouse cursor is over a certain picture and detect the click on/in the picture to change to a different picture without pasting code?

Code: [Select]
if ((0 < MouseX && MouseX < 162 && 124 < MouseY && MouseY < 260) && (Event.MouseButton.Button == sf::Mouse::Left) && (Jeopardy[1] == 1))
{
Question = 1;
JeopardyPos = 1;

};

if ((Event.MouseButton.Button == sf::Mouse::Right) && (Question > 0))
{
Jeopardy[JeopardyPos] = 0;
Question = 0;
};
        };


my implementation so far

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Drawing Everything
« Reply #32 on: May 21, 2008, 04:27:16 pm »
Quote from: "qsik"
it works now yay :)

now how would i implement getting if the mouse cursor is over a certain picture and detect the click on/in the picture to change to a different picture without pasting code?

Code: [Select]
if ((0 < MouseX && MouseX < 162 && 124 < MouseY && MouseY < 260) && (Event.MouseButton.Button == sf::Mouse::Left) && (Jeopardy[1] == 1))
{
Question = 1;
JeopardyPos = 1;

};

if ((Event.MouseButton.Button == sf::Mouse::Right) && (Question > 0))
{
Jeopardy[JeopardyPos] = 0;
Question = 0;
};
        };


my implementation so far


I know I already posted this...  You need to divide the mouse x and y coords by the cell size x and y to get what cell it was over.  If there's an offset from the top/left of the screen, just subtract it out.

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #33 on: May 21, 2008, 10:54:59 pm »
cell size?? i dont get what you're talking about

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Drawing Everything
« Reply #34 on: May 21, 2008, 11:01:25 pm »
Quote from: "qsik"
cell size?? i dont get what you're talking about


The size of each question tile/cell/area/sprite/whatever-you-want-to-call-it

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Drawing Everything
« Reply #35 on: May 21, 2008, 11:05:28 pm »
It only works if you have arranged your images into a regular 'grid' with a specific width and height for each. Then you can use integer division on the mouse position to get a 'cell' in the grid and find which image you are over.

If you have an irregular grid or no grid at all, what you probably want instead is (using boost FOREACH as it's easy):
Code: [Select]

BOOST_FOREACH(Sprite s, vSprites)
{
   if ((MouseX > s.GetLeft() && MouseX < s.(GetLeft()+s.GetWidth())) && (MouseY < s.GetTop() && MouseY > (s.GetTop()-s.GetHeight()))
   {
      //Mouse position is over this sprite, do something about it here
   }
}

As usual, this is written straight into the browser so please forgive me for any syntax errors or minor issues :)

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #36 on: May 22, 2008, 05:19:49 am »
i still don't get how to do it...

so lets say i have an 6x5 grid of images which are all 204 x 153, how would i do it then?

Code: [Select]
for (int image = 0; image < 25; image ++)
{
    if (image * category[image].GetWidth() < mousex < category[image].GetWidth()+204) && (image * category[image].GetHeight() < mousey < category[image].GetHeight()+153)
    {
        //Do Things Here
    }
}

Kernelpanic

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • http://eisenholz.bplaced.net
Drawing Everything
« Reply #37 on: May 22, 2008, 12:01:17 pm »
Code: [Select]

image * category[image].GetWidth() < mousex < category[image].GetWidth()+204

THis means true/false < category[image].GetWidth()+204

BloodGod

  • Newbie
  • *
  • Posts: 10
    • View Profile
Drawing Everything
« Reply #38 on: May 22, 2008, 03:02:41 pm »
Hi =)



At the bottom are the conditions that have to be true!

And here is an example function which determines whether the mouse is over a sprite or not:

Code: [Select]

inline bool Overlap(sf::Sprite s,const sf::Input& input)
{
if((input.GetMouseX() >= s.GetLeft() && input.GetMouseY() >= s.GetTop()) &&
(input.GetMouseX() <= s.GetLeft()+s.GetWidth() && input.GetMouseY() <= s.GetTop()+s.GetHeight()))
return true;
else
return false;
}


usage:
Code: [Select]

if(Overlap(Sprite, App.GetInput()) == true)
     std::cout << "yeah" << std::endl;


Sincerely,
BloodGod
Verlässt du dich auf andere, bist du selbst verlassen ;)

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #39 on: May 25, 2008, 05:48:55 pm »
lets say i have something on a flash drive, how do i make it so the program can access the media on the flash drive even though its letter changes? (ex. the flash drive is G:/flash drive on one computer and F:/flash drive on another and putting G:/flash drive in the code will cause an error on the computer that is F:/flash drive)

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Drawing Everything
« Reply #40 on: May 25, 2008, 06:28:25 pm »
Quote from: "qsik"
lets say i have something on a flash drive, how do i make it so the program can access the media on the flash drive even though its letter changes? (ex. the flash drive is G:/flash drive on one computer and F:/flash drive on another and putting G:/flash drive in the code will cause an error on the computer that is F:/flash drive)


Honestly, based on what you've posted so far, you're probably getting in way over your head with something like that.  Do you really need to do that?  If you must do something like that, google "boost filesystem"

Edit:  Thinking more about this, you are probably asking this question because you are (incorrectly) using absolute file paths.  You should only be using relative paths based on your working directory.  Then it doesn't matter where the app is stored (USB, HDD, network drive, whatever)

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #41 on: May 25, 2008, 11:26:20 pm »
it doesnt work because im using images from my flash drive but the working directory is C:

>>what do i do now?

>>EDIT>>also, it seems that GetLeft(), GetTop(), etc. have been removed, how do i substitue functions to return the same effect?

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Drawing Everything
« Reply #42 on: May 26, 2008, 01:43:16 am »
Quote from: "qsik"
it doesnt work because im using images from my flash drive but the working directory is C:

>>what do i do now?

>>EDIT>>also, it seems that GetLeft(), GetTop(), etc. have been removed, how do i substitue functions to return the same effect?


If the working directory is actually C: (which seems strange), just don't include the drive letter.  It doesn't matter what the working dir is.  Just reference all your files from that dir, not the root.
The answer to your second question is GetPosition().

qsik

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Drawing Everything
« Reply #43 on: May 26, 2008, 01:54:54 am »
sorry if i didnt make the post very clear

im making the program on my hard drive, directory C:

i have a flash drive attached where i copy the exe and it contains the images/music/etc. i need for the program

when using LoadFromFile("../../Jeopardy.bmp"), i get an access violation error during runtime

also, how does one use GetPosition()? i keep getting something about the position being a Vector2f?

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Drawing Everything
« Reply #44 on: May 26, 2008, 02:03:28 am »
Quote from: "qsik"
sorry if i didnt make the post very clear

im making the program on my hard drive, directory C:

i have a flash drive attached where i copy the exe and it contains the images/music/etc. i need for the program

when using LoadFromFile("../../Jeopardy.bmp"), i get an access violation error during runtime

also, how does one use GetPosition()? i keep getting something about the position being a Vector2f?


Well, if you are actually using C: as your directory, "../../Jeopardy.bmp" will cause an access violation since that references 2 directories up, which is impossible if you're starting at the root of C.

Edit:  I don't believe C: is actually your directory...