Game Development Asked by gamer1 on December 21, 2020
In my main class (game loop) I have created a couple of object textures:
//main game class
SDL_Texture* objectTexture;
SDL_Texture* objectTexture2;
If I do this in the main class (game loop) the texture doesn’t destroy itself, it leaves part of the animated SDL_Rect on the screen. This is the result of when the user clicks pick up on the menu.
gameObject = mob.PickUp(scene,x, y,gd, gy,mInteraction,spriteTexture,objectTexture,objectTexture2,renderer,spriteDown1, "");
if (gameObject != "") {
pob.DestroyObjects(gameObject, objectTexture, objectTexture2, renderer);
}
But if I do this in the main class, it works?
gameObject = mob.PickUp(scene,x, y,gd, gy,mInteraction,spriteTexture,objectTexture,objectTexture2,renderer,spriteDown1, "");
if (gameObject == "Object 1!"){
SDL_DestroyTexture(objectTexture);
objectTexture = SDL_CreateTextureFromSurface(renderer, NULL);
}
if (gameObject == "Object 2!"){
SDL_DestroyTexture(objectTexture2);
objectTexture2 = SDL_CreateTextureFromSurface(renderer, NULL);
}
pob.DestroyObjects does the same thing as above code, just in a different class. I have passed the pointers to the other class. I would be tearing my hair out but I have shaved my head during the lockdown.
it was due to the render in the game loop. I had to add a check before the render to confirm if the object had been picked up, so that not to keep rendering the object on each iteration of the game loop.
SDL_RenderCopy(renderer, objectTexture, &srcrect, &dstrect);
Answered by gamer1 on December 21, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP