1
Window / Re: [SFML2] Getting mouse position in a sf::RenderWindow
« on: July 11, 2011, 06:04:51 pm »
-snip- I figured it out. Thanks for the support anyway.
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.
Why are you using jpeg?
//Make pointers point to the grass and loam images in ImageHolder.h
iGrass = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\grass.png");
iLoam = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\loam.jpg");
//Make pointers point to the grass and loam images in ImageHolder.h
iGrass = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\grass.png");
iLoam = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\loam.png");
sf::Image *loadImage(char *path)
{
//Preload the Image
sf::Image imgHold;
if(!imgHold.LoadFromFile(path))
{
//Error
}
//If success:
else
{
//Checks for matching Image and returns
//100 if no image was found and the Image's location if it did.
int checkres = checkForImageMatch(path);
if(checkres == 100)
{
//If no match was found, find empty space to put image
//Returns 100 if there aren't any space
int elem = checkForNullImage();
if(elem != 100)
{
//Do the stuff to put the Image in
//the right space and catalouge the filename.
FileNameArray[elem] = path;
imgArray[elem].Copy(imgHold,0,0);
std::cout << "Image copy success! At: " << elem << std::endl;
//Return the address of that newly stored Image.
return &imgArray[elem];
}
else
{
//Error if there wasn't any space left...
std::cout << "NullCheck returned 100" << std::endl;
}
}
else
{
//If Image is already stored in memory, return the address
//to that image.
return &imgArray[checkres];
}
}
}
//Get the ImageHolder in main.cpp
map::map(ImageHolder *ImgHold)
{
//Make pointers point to the grass and loam images in ImageHolder.h
iGrass = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\grass.png");
iLoam = ImgHold->loadImage("C:\\Users\\Christian\\Documents\\Visual Studio 2008\\Projects\\NostrumEditor\\Debug\\loam.jpg");
//Make everything grass since I haven't made loading yet.
for(int i = 0;i<30;i++)
{
for(int j = 0;j<30;j++)
{
mapArray[i][j] = GRASS;
}
}
//For every element in the Sprite array set images and their positions
//Note: 0 is grass and 1 is loam
for(int i = 0;i<30;i++)
{
for(int j = 0;j<30;j++)
{
if(mapArray[i][j] == GRASS)
SpriteArray[i][j].SetImage(*iGrass);
else
SpriteArray[i][j].SetImage(*iLoam);
SpriteArray[i][j].SetPosition(i*32,j*32);
}
}
}
//Draw map by getting RenderWindow from main
//and using the sprites from this class.
//This is where I suspect the problem is.
void drawMap(sf::RenderWindow *App)
{
for(int i = 0;i<30;i++)
{
for(int j = 0;j<30;j++)
{
App->Draw(SpriteArray[i][j]);
}
}
}
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 800, 32),"Editor");
ImageHolder vImageHolder;
map curMap(&vImageHolder);
while(App.IsOpened())
{
//Event Handler
while (App.GetEvent(Event))
{
if(getKeyPressed(256))
{
App.Close();
}
}
curMap.drawMap(&App);
App.Display();
}
}