Entity LoadJellyfish() { Entity entity = new Entity("jellyfish"); Transform transform = entity.AddComponent <Transform>(); transform.Position = Screen.Center; SpriteAtlas atlas = SpriteAtlasLoader.ParseSpriteAtlas("Content/Mobs/Jellyfish/atlas/jellyfish.atlas", true); SpriteAnimator animator = new SpriteAnimator(atlas); entity.AddComponent(animator); transform.Origin = new Vector2(animator.TargetRectangle.Width * 0.5f, animator.TargetRectangle.Height * 0.5f); entity.AddComponent <Mover>(); CircleCollider circleCollider = new CircleCollider(); circleCollider.CollisionLayer = CollisionLayer.Jellyfish; entity.AddComponent(circleCollider); entity.AddComponent <Jellyfish>(); return(entity); }
Entity LoadPlayer() { Entity player = new Entity("player"); Transform transform = new Transform(); transform.Position = Screen.Center; player.AddComponent(transform); SpriteAtlas atlas = SpriteAtlasLoader.ParseSpriteAtlas("Content/Character/atlas/character.atlas", true); SpriteAnimator animator = new SpriteAnimator(atlas); animator.Play("idle"); player.AddComponent(animator); transform.Origin = animator.TargetRectangle.Size * 0.5f; player.AddComponent <Mover>(); PolygonCollider polygonCollider = new PolygonCollider(); polygonCollider.CollisionLayer = CollisionLayer.Player; player.AddComponent <PolygonCollider>(); player.AddComponent <Player>(); return(player); }
/// <summary> /// Loads a SpriteAtlas created with the Sprite Atlas Packer tool /// </summary> public SpriteAtlas LoadSpriteAtlas(string name, bool premultiplyAlpha = false) { if (LoadedAssets.TryGetValue(name, out var asset)) { if (asset is SpriteAtlas spriteAtlas) { return(spriteAtlas); } } var atlas = SpriteAtlasLoader.ParseSpriteAtlas(name, premultiplyAlpha); LoadedAssets.Add(name, atlas); DisposableAssets.Add(atlas); return(atlas); }
Entity LoadSquid() { Entity entity = new Entity("squid"); SpriteAtlas spriteAtlas = SpriteAtlasLoader.ParseSpriteAtlas("Content/Mobs/Squid/atlas/squid.atlas", true); SpriteAnimator spriteAnimator = new SpriteAnimator(spriteAtlas); entity.AddComponent(spriteAnimator); Transform transform = entity.AddComponent <Transform>(); transform.Origin = spriteAnimator.TargetRectangle.Size * 0.5f; transform.Position = new Vector2(Screen.Width * 0.5f, Screen.Height - 0.5f * spriteAnimator.TargetRectangle.Height); entity.AddComponent <Mover>(); entity.AddComponent <Squid>(); return(entity); }