AnswerBun.com

Trouble destroying an SDL2 texture from another class

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.

One Answer

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

Add your own answers!

Related Questions

Best way to save game data in Unity

1  Asked on February 28, 2021 by tair-galili

   

Unity – Sprite vertices in 3D world

1  Asked on February 24, 2021 by muckington

   

How to represent a modular FSM for AI using ECS?

2  Asked on February 22, 2021 by christian-ivicevic

       

get access to Transform of a Clone in Unity

1  Asked on February 21, 2021 by amin007

   

Box2d on authoritative server for Unity client

0  Asked on February 19, 2021 by antonio-agustin

         

How to Send Voice over Unity Networking – UNET

1  Asked on February 12, 2021 by muhammad-faizan-khan

         

Mathf.Clamp not Working Properly

1  Asked on February 3, 2021 by shubhendra-chaddha

   

SetTrigger Only Works In Start and Not OnTriggerEnter

1  Asked on February 3, 2021 by kit-k

       

How do I detect image clicks in Dark GDK?

1  Asked on February 2, 2021 by bobman

   

FIx color banding in unity

0  Asked on February 1, 2021

 

OnMouseOver not registering collisions

3  Asked on January 29, 2021 by hyperific

   

Call native code from Unity iOS build error

1  Asked on January 29, 2021 by atlantis

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir