Jump to content
  • Advertisement
Sign in to follow this  

Sprite class [a proper and complete implementation]

This topic is 2817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I was wondering about the proper implementation of parents/children in a sprite class, beyond the usual members of a sprite class, such as Position, Texture2D, Rotation, and etc.

What I was personally planning on doing was to simply add two new members:

Sprite Parent;
List<Sprite> Children

And then of course, change all the members to look more like this (Alpha member example):

get {
if (Parent != null) return Parent.Alpha * this.alpha;
else return this.alpha;

At first I thought this wasn't such a bad idea (how else would such a class be implemented/structured?) but with this example in particular (alpha), drawing a Sprite where, say, alpha = 0.5, and which has many children, will result in each child Sprite blending into each other, since all of their alpha values are now at 50%

The desired result is that the object as a whole would be at 50% transparency and blends only with the background, and not with Objects that are within itself.

I thought of each parent Sprite object to be drawn to a Texture2D using a render target, and then applying the alpha to the Texture2D instead. That way, the object as a whole would have a transparency of 50% and not every child Sprite. But to have each Sprite applied to a Texture2D using a render target... would such a thing not be very taxing on the cpu?

My question then is... what is the best implementation of a Sprite class that has this functionality? It really is basically trying to replicate the MovieClip class in AS3. How could this be replicated in C#/XNA?

Thanks. Any help/input would be appreciated.

Share this post

Link to post
Share on other sites
What is best really depends on you and your project.

There is no one-size-fits-all object.

Maybe for you it is a duplicate of a Flash clip -- in which case maybe you would be better off with Flash, or binding to flash with FlashBuilder.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!