C
C#2y ago
Sev

❔ does an interface go inside a generic parent class?

using Godot;
using System;

public class StateTemplate : Node
{
public enum State {
Null,
Idle,
Run,
Fall,
Jump,
Dodge
}
[Export]
private String animation_name;
public Player Player;

public void enter()
{
Player.AnimSprite.Play(animation_name);
}
public void exit()
{}
public int processInput(InputEvent @event)
{
return (int)State.Null;
}
public int doProcess(float delta)
{
return (int)State.Null;
}
public int processPhysics(float delta)
{
return (int)State.Null;
}
}
using Godot;
using System;

public class StateTemplate : Node
{
public enum State {
Null,
Idle,
Run,
Fall,
Jump,
Dodge
}
[Export]
private String animation_name;
public Player Player;

public void enter()
{
Player.AnimSprite.Play(animation_name);
}
public void exit()
{}
public int processInput(InputEvent @event)
{
return (int)State.Null;
}
public int doProcess(float delta)
{
return (int)State.Null;
}
public int processPhysics(float delta)
{
return (int)State.Null;
}
}
here is the parent class for my state machine, all states will have a processInput() and processPhysics, do I create an IState interface inside or outside of parent class? I ask because I am translating this from another language and I think this is a pseudo interface
5 Replies
Angius
Angius2y ago
Interfaces are, usually, placed in a separate file Also, as a side note, C# uses PascalCase for method names And lowercase string
Sev
Sev2y ago
Alright my next question is where do I implement the interface? Do I do so in the parent class in code above or do I do it each time for each child class?
Angius
Angius2y ago
Whichever you prefer Interfaces are inherited by the children of the class that implements them, though If Foo implements IFoo, then Bar : Foo also implements IFoo
Sev
Sev2y ago
makes sense. thanks
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts