# re-using objects

I'm working with openGL ES 2.0 on Android and I've created a custom Quad class.

This allows me to make a sprite object like so:

Quad mySprite = new Quad();
mySprite.setSize(w,h);
mySprite.setTexture(myTexture);


Then, I can draw it like so:

mySprite.draw();


The draw() method uses mySprite's internal x and y coordinates which are declared within the Quad Class.

I also have another method which allows me to draw the quad specifying other 'external' co-ordinates like so:

mySprite.draw(x,y);


Now let's say that on one of the levels of my game, I have the need to draw 3 of these sprites at different positions and move them all independently of each other.

At the moment, I think I have 2 options, which are:

1) Create different quad's with the same texture and use them with their internal coordinates or....

2) Use the same object but hold an array of external coordinates and just draw it three times at different places.

My preferred option would be 1 because it's just cleaner to work with but clearly inefficient as I'm having to create multiple objects that are essentially the same (inefficient memory-wise?)

So is there a way of using just one version of the sprite? Maybe using clones or something along those lines so that I can just keep track of each clone's internal position and states rather than using external arrays?

• How much memory does Quad take up? If it's lightweight, I don't think it would be an issue to have multiple instances of it. If it's not, create a lightweight wrapper around Quad. – Vittorio Romeo Jul 6 '13 at 1:44
• Hi @VittorioRomeo thank you for your comment, I was under the impression Wrapper classes were relating to primitives, could you please explain how I would use this concept with my custom class - if there were only one of two objects of this class I would just create different objects but I can see on certain levels I may need like 20+ so would prefer a better solution to just creating different objects! Please could you explain how a wrapper would help in this situation? Thanks! – BungleBonce Jul 6 '13 at 12:07