Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:27:13+00:00 2026-05-29T06:27:13+00:00

I have a basic core interface called IComponent. public interface IComponent { void Initialize();

  • 0

I have a basic core interface called IComponent.

public interface IComponent
{
    void Initialize();

    void Update();

    void Draw(Color tint);

    BoundingBox BoundingBox { get; }

    bool Initialized { get; }
}

It is used by any class that will drawable (button, text, texture, …)

I want to develop a set of effects that can be applied to any IComponent, such as:

Shake(IComponent component, TimeSpan duration)

-> Causes the Component to vibrate for a given duration. It works by initially storing the center position of the passed component and offsetting it at each Update till duration ends.

Translate(IComponent component, Vector2 destination, TimeSpan timeToReach)

-> Causes the Component to move to the given destination after a certain time. It works by incrementally offsetting the component at each Update.

You can imagine more…

So assume I want a certain class (Texture : IComponent) to shake while also moving to a certain point. I thought of possibly using the decorator pattern like so:

Create a Texture => Wrap it in a Shake (5 sec duration) => Wrap it in a Translate (10 sec duration)

but there are some problems with that.

Primarily, The Shake wrapper would work fine alone with a static stationary texture, but combined with a Translate it would fail since it would keep returning the texture to its original position and it wont translate properly.

Secondly, while the translation will take 10 seconds to finish, the vibrating will take only 5 seconds, so afterwards I don’t know how to automatically remove the Shake wrapper from within the chain, and also finally remove the Translate when its done, leaving behind the original texture.

Thirdly, the decorator pattern hides any specific functions of the wrapped object, so after wrapping a Texture with a Shake, I wont be able to invoke the setPixelColor() of Texture, unless I also create a second direct reference to Texture before wrapping it.

Any suggestions of how to tackle such a challenge elegantly are welcome. Thanks.

Note: In practice I am likely to apply those effects to probably 2% of all created objects that are IComponent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:27:13+00:00Added an answer on May 29, 2026 at 6:27 am

    Maybe another approach along the following lines.

    In your example both shake and translate are Animation effects. All animations need some form of duration and are applied to a component. Which could lead to the following first take:

    public interface IAnimationEffect
    {
        IComponent targetComponent;
        int Duration { get; set; }
    }
    

    Duration of an animation may seem like a good initial approach, however, when you need to combine animations, each animation needs to manipulate the BoundingRect of its encapsulated IComponent over the same period of time as other animations. In order to be able to stack animations like this, the draw methods for the animation effects need to be instructed to draw a specific frame of the animation.

    An improved version of the IAnimationEffect interface would be:

    public interface IAnimationEffect
    {
        IComponent targetComponent;
        int StartFrame { get; set; }
        int EndFrame { get; set; }
        void CalculateFrame(int frame);
    }
    

    Whichever class is responsible for drawing your IComponents (Lets call it DrawingEngine for now), is now also responsible for holding an internal List of all applicable animation effects. It also needs to have some sort of timeline and rendering logic in frames per second, so that calculations for a specific animation frame can be performed.

    public class ShakeAnimationEffect : IAnimationEffect
    {
        public IComponent TargetComponent { get; set; }
        public int StartFrame { get; set; }
        public int EndFrame { get; set; }
        // Some shake specific properties can be added, to control the type of vibration etc 
        // (could be a rotating vibration an updown shake), but these really should have dedicated classes of their own.
    
        public void CalculateFrame(int frame)
        {
            // your maths manipulations for calculating the bounds of the IComponent go here
        }
    }
    
    public class TranslateAnimation : IAnimationEffect
    {
        public IComponent targetComponent { get; set; }
        public int StartFrame { get; set; }
        public int EndFrame { get; set; }
        public int TranslateX { get; set; } 
        public int TranslateY { get; set; }
    
        public void CalculateFrame(int frame)
        {
            // your maths manipulations for calculating the bounds of the IComponent go here
        }
    }
    

    As proposed above then your AnimationEffects classes do not have any responsibility for drawing IComponents, that remains the responsibility of the DrawingEngine.

    What you would need to introduce directly before your DrawingLoop, is a loop for running all animation effects, all this would do is update the bounds of the objects that happen to have an animation effect associated with them. Then you carry on drawing the object as usual.

    Suppose that you have something like this:

            // suppose your drawing engine has the following:
           List<IComponent> components = new List<IComponent>();
    
            //now just add the following 
           List<IAnimationEffect> animationEffects = new List<IAnimationEffect>(); 
    
            // create some animation effects and register them to your list
            animationEffects.Add(new ShakeAnimationEffect
              {
                  TargetComponent = Lorry,
                  StartFrame = 0,
                  EndFrame = 150, //At 30 frames per second, this would be a 5sec animation
              }
            );
    
            //sample pseudecode
            RunAnimationCalculations();
            RunDrawingLoop();
    

    All that RunAnimationCalculations would do is loop through through your animationEffects collection and run Calculate passing in the current frame so that the bounds of the IComponent are updated, before the frame is subsequently drawn.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic CRUD form that uses PageMethods to update the user details,
I'm trying to do some basic quartz core drawing with arcs, but have an
I have this very basic problem, >>> from django.core import serializers >>> serializers.serialize(json, {'a':1})
I have a basic Core data model like this: Class -Class Name (string) Relationship:
I have this basic one-to-many relationship in Core Data: Brand has N Products Product
I have some basic questions about core data (which I am new to) and
I have a basic question regarding populating Core Data with data. I am building
I have basic idea on Kilo Virtual Machine on Mobiles , I have clear
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic form with controls that are databound to an object implementing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.