I am working on my first game. I have been stuck for the last few hours and I just cannot figure out how to redraw my sprite in a separate thread. First I created a struct with a bunch of pointers. Then I set up a new thread and passed the struct in. Everything worked great until I tried to redraw the sprite.
Whenever I try to access the sf::RenderWindow.Draw Function, I don't have the right Object type to pass in. It needs a reference to a Sprite Object, and I only have a pointer.
I tried converting it with a line like the one below but the compiler rejected it with this message: error C2440: 'initializing' : cannot convert from 'sf::Sprite *' to 'sf::Sprite &'
Sprite& rPlayer (pSprite);
I tried not using a pointer and just including a Sprite Object in the Struct. It compiled but when the thread launched, the program froze up for a few seconds, and gave me a bunch of OpenGL error messages in the console window. I can't figure out what to do with my Pointer so I can pass my sprite in to the sf::RenderWindow.Draw function a separate thread.
Any Help would be greatly appreciated!
My Code looks something like this.
struct UserData{
int* pMap;
RenderWindow* pApp;
Sprite* pSprite;
AnimationClass* pAnimator;
};
void ThreadFunction(void* UserData)
{
for (int i = 0; i < 10; ++i)
{
Data->pAnimator->myAnimation(pSprite);
Data->pApp->Draw(???????What can I pass in here???????);
}
}
int main()
{
UserData Data = { pMap, pApp, pSprite, pAnimator };
sf::Thread myThread(&ThreadFunction, &Data);
myThread.Launch();
return EXIT_SUCCESS;
}