© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3mo ago•
1 reply
BigBoyConst

Question about base class references

visual studiointermediate
My OOP class is a little far in my memory, we probably talked about something like this but its the kind of issue that I run into so rarely that I completely forgot how to solve it (if its possible).
Long story short, I'm making an animation engine that's kind of the C# version of Manim (or, at least, I'm trying to) and I wanted to make an animation which creates a line by interpolating its end point from its start point to whatever the target end point is.
The way an animation works conceptually is that I describe its initialization and finalization
Start()
Start()
and
End()
End()
methods, and then I update the target object's state with the
Update(float dt)
Update(float dt)
method.
The issue (i think, at least) is rooted in the fact that the base
Animation
Animation
class takes in a
FrameObject
FrameObject
(the base class for every object, including
Line
Line
), but the line creation animation takes in a
Line
Line
, since it obviously wouldn't make sense to apply this function to a circle or something.
What I tried doing was something like this
class LineCreate : Animation 
{
    Line l => AssertTargetIsLine(Target);
    Vector2 finalEnd;

    static Line AssertTargetIsLine(FrameObject target) 
    {
        if (target is not Line l)
            throw new Exception("Target object must be a line");
        return l;
    }
    
    public override void Start() 
    {
        finalEnd = l.End;
        l.InterpolateEnd(0, finalEnd);
        base.Start();
    }

    public override void Update(float dt)
    {
        float percent = LocalTime / Duration;
        percent = EaseFunc(percent);
        l.InterpolateEnd(percent, finalEnd);
        base.Update(dt);
    }

    public override void End()
    {
        l.InterpolateEnd(1, finalEnd);
        base.End();
    }
}
class LineCreate : Animation 
{
    Line l => AssertTargetIsLine(Target);
    Vector2 finalEnd;

    static Line AssertTargetIsLine(FrameObject target) 
    {
        if (target is not Line l)
            throw new Exception("Target object must be a line");
        return l;
    }
    
    public override void Start() 
    {
        finalEnd = l.End;
        l.InterpolateEnd(0, finalEnd);
        base.Start();
    }

    public override void Update(float dt)
    {
        float percent = LocalTime / Duration;
        percent = EaseFunc(percent);
        l.InterpolateEnd(percent, finalEnd);
        base.Update(dt);
    }

    public override void End()
    {
        l.InterpolateEnd(1, finalEnd);
        base.End();
    }
}

However, the line isn't updating. I know the issue isn't the methods for moving the endpoint, so i feel that it has to be that the reference is not the same, but i'm not sure what to do to solve this.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Base Class architecture
C#CC# / help
2y ago
Yet another question about struct & class
C#CC# / help
2y ago
❔ C# Inheritance Topic Question Mostly about base constructors
C#CC# / help
3y ago
Mocking derived class with abstract base class
C#CC# / help
4y ago