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

Show Posts

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.


Messages - chrbarrol

Pages: [1]
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.

2
Window / [SFML2] Getting mouse position in a sf::RenderWindow
« on: July 11, 2011, 03:26:04 pm »
I recently switched over to SFML2 (which I might say has a lot of great features) but while I was trying to get the mouse position in my sf::RenderWindow I noticed that the mouse position code had been rewritten, so as far as I can tell from the documentation the sf::mouse is supposed to return the mouse's position from the window it is focused in.

But when I tried it out, GetPosition would just return the mouse's position on the screen(0,0 was always top left of the screen regardless of what window the cursor was in) I also noticed you could get the position for a specific window but only for a sf::Window and not a sf::RenderWindow. Does anyone know of a way to make this work? I'd rather not write a huge workaround that gets the window's position and normalizes the mouse based on that.

3
Graphics / Drawing form custom class lags the program up...
« on: January 31, 2011, 10:40:16 pm »
:shock: Oh wow can't see how I missed that, then there's really no problem, still kinda strange about that whole jpg thing though.

4
Graphics / Drawing form custom class lags the program up...
« on: January 31, 2011, 09:16:52 pm »
Here's the most lightweight version I bothered making:
http://dl.dropbox.com/u/5168131/source.zip

Just put the images in the same folder as the exe I'm guessing you can figure the rest out by yourselves.

Hope someone has the time to look over it. :)
Also for some reason even though I started using only PNG again it started lagging now I'm really confused since I can't remember doing anything to it...

5
Graphics / Drawing form custom class lags the program up...
« on: January 31, 2011, 08:11:32 am »
Quote from: "Disch"
Why are you using jpeg?


It was only a dev build never would've thought it would make such a difference. Just thought I'd get it out there just in case you guys didn't know(which you did)

6
Graphics / Found bug possibly...
« on: January 30, 2011, 09:35:33 pm »
I don't know but I think I might have stumbled upon a bug...

When I changed the picture format of loam.jpg to loam.png all the lag disappeared. I decided to try it out again so I changed it back to jpg form again and guess what, it started lagging again.

Any idea why this might happen?

Code changed from:
 
Code: [Select]
//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");

To:
Code: [Select]
//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");

7
Graphics / Drawing form custom class lags the program up...
« on: January 30, 2011, 06:30:12 pm »
I'm currently making a 2d game and I'm currently in the process of making the map class that draws on the screen when the function drawMap() is called in the main class.

But when I run the program it starts lagging to the point when I can't almost press escape to quit...

Here's the code used to draw and get Images:

In ImageHolder.h
Code: [Select]
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];
}

}

}


In map.h
Code: [Select]
//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);

}

}
}


Code: [Select]
//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]);
}

}
}


In main.cpp
Code: [Select]
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();
}



}


What I suspect the problem is, is that for some reason it copies the images I use in every loop which I don't understand why it does...

Might have something to do with "App->Draw(SpriteArray[j]);"

Also even though it lags, I can see all the images and their positions are correct.

Also please excuse my poor code syntax I've only coding for half a year.

Pages: [1]
anything