@Coda wrote:
Hello guys, i'm pretty new to MonoGame, coming from a LibGDX background.
While working on a 2D side-scroller, I came-up with a little problem: Resource Managment.
I have one Singleton class named ResourceManager. Something like:public class ResourceManager { private Dictionary<string, Texture2D> mTextures; //Get/Set Texture code //Singleton Code }
After that, I have some entities, like Player that uses ResourceManager like this:
public class Player : Entity { //Some code here private Animation mWalkingAnimation; private Animation mHeadWalkingAnimation; public Player() { Texture2D texture = ResourceManager.Instance.GetTexture("character_full"); mWalkingAnimation = new Animation(texture, 1.0f / 6.5f); mWalkingAnimation.AddFrame(new Rectangle(40, 18, 18, 46)); mWalkingAnimation.AddFrame(new Rectangle(74, 18, 11, 46)); mWalkingAnimation.AddFrame(new Rectangle(107, 18, 10, 46)); mWalkingAnimation.AddFrame(new Rectangle(136, 18, 18, 46)); mWalkingAnimation.AddFrame(new Rectangle(170, 18, 11, 46)); mWalkingAnimation.AddFrame(new Rectangle(203, 18, 9, 46)); standAnimation = new Animation(texture, 1.0f / 1.0f); animation.AddFrame(new Rectangle(7, 18, 16, 48)); texture = ResourceManager.Instance.GetTexture("head_hair_dark"); mHeadWalkingAnimation= new Animation(texture, 1.0f / 8.0f); mHeadWalkingAnimation.AddFrame(new Rectangle(4, 30, 17, 34)); mHeadWalkingAnimation.AddFrame(new Rectangle(34, 30, 20, 34)); mHeadWalkingAnimation.AddFrame(new Rectangle(69, 29, 13, 35)); mHeadWalkingAnimation.AddFrame(new Rectangle(100, 29, 15, 35)); mHeadWalkingAnimation.AddFrame(new Rectangle(130, 30, 20, 34)); } }
(Avoid the Head Walking Animation, i know it should be in some sort of Item object, it was just for testing).
Is there a better way of handling resources?
Another question is, do you think I should create general animation variables (like mWalkingAnimation, mStandingAnimation, etc) in Entity?
Posts: 1
Participants: 1