public OtherPlayerEntity(CharacterPlayer others) : base(others._name) { others.MaxHealth = 100; other = others; TextComponent textComponent = new TextComponent(Graphics.Instance.BitmapFont, others._name, Vector2.Zero, Color.White); //HealthtextComponent = new TextComponent(Graphics.Instance.BitmapFont, others.CurrentHealth.ToString(), Vector2.Zero, Color.White); this.SetPosition(others.physicalPosition); AddComponent(new OtherPlayerComponent(others)); AddComponent(textComponent); //AddComponent(HealthtextComponent).SetHorizontalAlign(HorizontalAlign.Left).SetVerticalAlign(VerticalAlign.Bottom).SetRenderLayer(-2); SetTag(7); this.SetScale(3.5f); SpriteAnimation Idle = TextureContainer.GetSpriteAtlasByName("Knight").GetAnimation("Idle"); SpriteAnimation Movement = TextureContainer.GetSpriteAtlasByName("Knight").GetAnimation("Movement"); SpriteAnimator animator = AddComponent <SpriteAnimator>(); animator.AddAnimation("Idle", Idle); animator.AddAnimation("Movement", Movement); animator.Play("Idle"); }
private void SetupAnimations() { this.animator = new SpriteAnimator() { RenderLayer = Constants.Layer_NPC }; var runTexture = Scene.Content.LoadTexture(ContentPaths.Doctor + "DocRun.png"); var runSprites = Sprite.SpritesFromAtlas(runTexture, 20, 28); animator.AddAnimation("Run", runSprites.ToArray()); var attackTexture = Scene.Content.LoadTexture(ContentPaths.Doctor + "DocAttack.png"); var attackSprites = Sprite.SpritesFromAtlas(attackTexture, 54, 30); for (int i = 0; i < 3; i++) { animator.AddAnimation($"Attack{i}", attackSprites.GetRange(i * 7, 7).ToArray()); } var hurtTexture = Scene.Content.LoadTexture(ContentPaths.Doctor + "DocHurt.png"); var hurtSprites = Sprite.SpritesFromAtlas(hurtTexture, 19, 27); hurtSprites.AddRange(hurtSprites); animator.AddAnimation("Hurt", 20, hurtSprites.ToArray()); animator.AddAnimation("Idle", 8, attackSprites[0]); this.renderer = animator; AddComponent(animator); animator.Play("Run"); animator.OnAnimationCompletedEvent += AnimationCompleted; }
public void PlayAnimationTestIfPlayingWrong() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); FrameAnimation animation2 = new FrameAnimation(5f, false, 1, 10); animator.AddAnimation("test", animation); animator.AddAnimation("testWrong", animation2); animator.PlayAnimation("test"); Assert.IsFalse(animator.IsAnimationPlaying("testWrong")); }
/// <summary> /// Add animations to SpriteAnimator. /// </summary> private void SetupAnimations() { var atlasTexture = Entity.Scene.Content.LoadTexture(@"Content\Textures\DemonChicken.png"); var animationSprites = Sprite.SpritesFromAtlas(atlasTexture, 120, 113).ToArray(); animator.AddAnimation(PlayerState.Idle.ToString(), new SpriteAnimation(new[] { animationSprites[0], animationSprites[1], animationSprites[2] }, 8f)); animator.AddAnimation(PlayerState.Running.ToString(), new SpriteAnimation(new[] { animationSprites[3], animationSprites[4], animationSprites[5], animationSprites[6] }, 10f)); animator.AddAnimation("Attack", new SpriteAnimation(new[] { animationSprites[7], animationSprites[8], animationSprites[9], animationSprites[10], animationSprites[11], animationSprites[12], animationSprites[13] }, 10f)); animator.AddAnimation(PlayerState.Dead.ToString(), new SpriteAnimation(new[] { animationSprites[14], animationSprites[15], animationSprites[16], animationSprites[17], animationSprites[18], animationSprites[19], animationSprites[20], animationSprites[21], animationSprites[22], animationSprites[23], animationSprites[24], animationSprites[25], animationSprites[26], animationSprites[27], animationSprites[28], animationSprites[29], animationSprites[30], animationSprites[31], }, 10f)); }
public override void OnAddedToEntity() { base.OnAddedToEntity(); SpriteAnimator animator = Entity.AddComponent(new SpriteAnimator()); var animationSprites = Sprite.SpritesFromAtlas(tex, 64, 64).ToArray(); animator.AddAnimation("idle", new [] { animationSprites[0], animationSprites[1] }, 1); animator.AddAnimation("dead", new [] { animationSprites[2] }); animator.Play("idle", SpriteAnimator.LoopMode.Loop); }
private void InitializeAnimations() { var n = Random.NextInt(20); var texture = Entity.Scene.Content.LoadTexture(ContentPaths.CivilianSheet); var sprites = Sprite.SpritesFromAtlas(texture, 32, 32).Where((s, i) => i % 20 == n).ToList(); // TODO: Separate idle into blink and eyes open (blink periodically) animator.AddAnimation("Idle", 3, Utility.SelectFromList(sprites, 0, 0, 0, 1, 2).ToArray()); animator.AddAnimation("Shock", Utility.SelectFromList(sprites, 5, 6, 7, 7).ToArray()); animator.AddAnimation("Celebration", 2, Utility.SelectFromList(sprites, 9, 10, 10, 10).ToArray()); animator.AddAnimation("Walking", sprites.GetRange(11, 6).ToArray()); animator.Play("Idle"); }
public override void OnAddedToEntity() { // load up our character texture atlas. we have different characters in 1 - 6.png for variety var characterPng = Random.Range(1, 7); var texture = Entity.Scene.Content.Load <Texture2D>("NinjaAdventure/characters/" + characterPng); var sprites = Sprite.SpritesFromAtlas(texture, 16, 16); _mover = Entity.AddComponent(new Mover()); _animator = Entity.AddComponent <SpriteAnimator>(); // add a shadow that will only be rendered when our player is behind the details layer of the tilemap (RenderLayer -1). The shadow // must be in a renderLayer ABOVE the details layer to be visible. var shadow = Entity.AddComponent(new SpriteMime(Entity.GetComponent <SpriteRenderer>())); shadow.Color = new Color(10, 10, 10, 80); shadow.Material = Material.StencilRead(); shadow.RenderLayer = -2; // ABOVE our tiledmap layer so it is visible // extract the animations from the atlas _animator.AddAnimation("WalkLeft", new[] { sprites[2], sprites[6], sprites[10], sprites[14] }); _animator.AddAnimation("WalkRight", new[] { sprites[3], sprites[7], sprites[11], sprites[15] }); _animator.AddAnimation("WalkDown", new[] { sprites[0], sprites[4], sprites[8], sprites[12] }); _animator.AddAnimation("WalkUp", new[] { sprites[1], sprites[5], sprites[9], sprites[13] }); SetupInput(); }
public AbilityAnimationEntity(AbilityHead ability, Entity target, Vector2 source) { this.ability = ability; this.target = target; this.SetScale(0.25f); this.source = source; switch (ability.ID) { case 1: animation = TextureContainer.GetSpriteAtlasByName("FireBall").GetAnimation("travel"); break; default: break; } float deltaX = target.Position.X - source.X; this.SetPosition(source); animator = AddComponent <SpriteAnimator>(); if (deltaX > 0) { animator.FlipX = true; } animator.AddAnimation("travel", animation); animator.Play("travel"); }
public void AddAnimationTestFirstAsCurrentAnimation() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); animator.AddAnimation("test", animation); Assert.AreEqual(animation, animator.CurrentAnimation, "Animacija nepridėta arba sąrašas nebuvo tuščias"); }
public void PlayAnimationTestNotExistant() { SpriteAnimator animator = new SpriteAnimator(); FrameAnimation animation = new FrameAnimation(2f, false, 1, 10); animator.AddAnimation("test", animation); animator.PlayAnimation("wrongName"); }
public static SpriteAnimator AddAnimationSet(this SpriteAnimator animator, AnimationSet set) { for (int i = 0; i < set.Count; i++) { animator.AddAnimation(set.name + i, set[i]); } return(animator); }
public override void OnAddedToEntity() { base.OnAddedToEntity(); SpriteAnimator animator = Entity.AddComponent(new SpriteAnimator()); var animationSprites = Sprite.SpritesFromAtlas(tex, 64, 64).ToArray(); animator.AddAnimation("dance", animationSprites); animator.Play("dance", SpriteAnimator.LoopMode.PingPong); }
public override void Initialize() { base.Initialize(); animator.AddAnimation("1", new[] { sprites[0] }); animator.AddAnimation("2", new[] { sprites[1] }); animator.AddAnimation("3", new[] { sprites[2] }); animator.AddAnimation("4", new[] { sprites[3] }); animator.AddAnimation("5", new[] { sprites[4] }); var colSprite = Sprite.SpritesFromAtlas(new Sprite(Core.Content.LoadTexture("Data/sprites/pips_col.png")), 16, 16); colAnimator = new SpriteAnimator(colSprite[0]); colAnimator.AddAnimation("1", new[] { colSprite[0] }); colAnimator.AddAnimation("2", new[] { colSprite[1] }); colAnimator.AddAnimation("3", new[] { colSprite[2] }); colAnimator.AddAnimation("4", new[] { colSprite[3] }); colAnimator.AddAnimation("5", new[] { colSprite[4] }); }
private void SetupTextures() { this.animator = new SpriteAnimator(); var texture = Scene.Content.LoadTexture(ContentPaths.Crosshair_Vertical); var sprites = Sprite.SpritesFromAtlas(texture, 16, 16); animator.AddAnimation("Vertical", 2, sprites.ToArray()).Play("Vertical"); texture = Scene.Content.LoadTexture(ContentPaths.Crosshair_Diagonal); sprites = Sprite.SpritesFromAtlas(texture, 16, 16); animator.AddAnimation("Diagonal", 12, sprites.ToArray()); texture = Scene.Content.LoadTexture(ContentPaths.Crosshair_Transition); sprites = Sprite.SpritesFromAtlas(texture, 12, 12); animator.AddAnimation("TransitionTo", 30, sprites[0]); animator.AddAnimation("TransitionBack", 30, sprites[1]); animator.OnAnimationCompletedEvent += FinishTransition; AddComponent(animator); }
public PlayerEntity(CharacterPlayer player) { this.player = player; TextComponent textComponent = new TextComponent(Graphics.Instance.BitmapFont, player._name, Vector2.Zero, Color.White); HealthtextComponent = new TextComponent(Graphics.Instance.BitmapFont, player.CurrentHealth.ToString(), Vector2.Zero, Color.White); SetTag(2); this.SetPosition(player.physicalPosition); AddComponent(textComponent).SetHorizontalAlign(HorizontalAlign.Center).SetVerticalAlign(VerticalAlign.Top).SetRenderLayer(-200); AddComponent(new PlayerComponent()); AddComponent(HealthtextComponent).SetHorizontalAlign(HorizontalAlign.Right).SetVerticalAlign(VerticalAlign.Bottom).SetRenderLayer(-200); SpriteAnimation Idle = TextureContainer.GetSpriteAtlasByName("Knight").GetAnimation("Idle"); SpriteAnimation Movement = TextureContainer.GetSpriteAtlasByName("Knight").GetAnimation("Movement"); SpriteAnimator ani = textComponent.AddComponent <SpriteAnimator>(); ani.AddAnimation("Idle", Idle); ani.AddAnimation("Movement", Movement); ani.Play("Idle"); this.SetScale(3.5f); }
public override void OnAddedToEntity() { // load up our character texture. var texture = Entity.Scene.Content.Load <Texture2D>("Textures/DinoSprites - tard"); var sprites = Sprite.SpritesFromAtlas(texture, 24, 24); //Entity.AddComponent<SpriteRenderer>(new SpriteRenderer(texture)); Entity.SetLocalScale(new Vector2(2.0f, 2.0f)); _mover = Entity.AddComponent(new Mover()); _camera = Entity.AddComponent(new FollowCamera()); _animator = Entity.AddComponent <SpriteAnimator>(); _animator.SetRenderLayer(-20); _animator.AddAnimation("Walk", new[] { sprites[4], sprites[5], sprites[6], sprites[7], sprites[8], sprites[9] }); _animator.AddAnimation("Damage", new[] { sprites[14], sprites[15], sprites[16] }); _animator.AddAnimation("Crouch", new[] { sprites[18], sprites[19], sprites[20], sprites[21], sprites[22], sprites[23] }); _animator.AddAnimation("Transition", new[] { sprites[17] }); _animator.AddAnimation("Idle", new[] { sprites[0], sprites[1], sprites[2], sprites[3], }); _animator.AddAnimation("Kick", new[] { sprites[10], sprites[11], sprites[12], sprites[13] }); SetupInput(); }
public override void OnAddedToEntity() { Console.Write("PLAYER"); base.OnAddedToEntity(); var texture = Entity.Scene.Content.Load <Texture2D>("Sprites/Characters/charactersheet"); // frames of all the sprites are the same size... 16 x 16 var sprites = Sprite.SpritesFromAtlas(texture, 16, 16); SpriteAnimator animator = this.AddComponent <SpriteAnimator>(); animator.AddAnimation("walkDown", new[] { sprites[12], sprites[13], sprites[12], sprites[14] }, 1.0f); animator.Play("walkDown"); mover = this.AddComponent(new Mover()); this.AddComponent <CircleCollider>(); SetupInput(); }
public void AddAnimationTestAddMultipleAnimationParametrized(int num) { SpriteAnimator animator = new SpriteAnimator(); Dictionary <string, FrameAnimation> animDict = new Dictionary <string, FrameAnimation>(); FrameAnimation[] animations = new FrameAnimation[num]; for (int i = 0; i < num; i++) { string name = "name" + i; FrameAnimation anim = new FrameAnimation(10f, false, i, 20 * i); animDict.Add(name, anim); animator.AddAnimation(name, anim); } Assert.IsTrue(animDict.All(x => animator.IsAnimationInList(x.Key) == true)); }
public SlimeSpriteController(SpriteAnimator spriteAnimator) : base(spriteAnimator) { Texture2D texture = Core.Content.Load <Texture2D>("Objects/Characters/Monsters/monster_spritesheet"); List <Sprite> sprites = Sprite.SpritesFromAtlas( texture, SpriteSize.X, SpriteSize.Y); SpriteAnimator.AddAnimation(WalkForwardAnimation, new[] { sprites[0], sprites[1], sprites[2], }); SpriteAnimator.AddAnimation(IdleForwardAnimation, new[] { sprites[1] }); SpriteAnimator.AddAnimation(WalkSideAnimation, new[] { sprites[3], sprites[4], sprites[5] }); SpriteAnimator.AddAnimation(IdleSideAnimation, new[] { sprites[4] }); SpriteAnimator.AddAnimation(WalkBackwardAnimation, new[] { sprites[9], sprites[10], sprites[11] }); SpriteAnimator.AddAnimation(IdleBackwardAnimation, new[] { sprites[10] }); }
public AttackSpriteController(SpriteAnimator animator) : base(animator) { Texture2D texture = Core.Content.Load <Texture2D>("Objects/Characters/effect_spritesheet"); List <Sprite> sprites = Sprite.SpritesFromAtlas( texture, SpriteSize.X, SpriteSize.Y); SpriteAnimator.AddAnimation(SlashForward, new[] { sprites[0], sprites[1], sprites[2], sprites[4] }); SpriteAnimator.AddAnimation(SlashSide, new[] { sprites[12], sprites[13], sprites[14], sprites[15] }); SpriteAnimator.AddAnimation(BiteForwardAnimation, new[] { sprites[24], sprites[25], sprites[26], sprites[27], }); SpriteAnimator.AddAnimation(BiteForwardAnimation, new[] { sprites[36], sprites[37], sprites[38], sprites[39], }); }
public override void OnAddedToEntity() { var texture = Entity.Scene.Content.Load <Texture2D>("sprites"); var sprites = crearSprites(texture); _animator = Entity.AddComponent(new SpriteAnimator(sprites[0])); _animator.AddAnimation("none", new[] { sprites[0] }); _animator.AddAnimation("correr", new[] { sprites[1] }); _animator.AddAnimation("arma1", new[] { sprites[2] }); _animator.AddAnimation("arma2", new[] { sprites[3] }); _animator.AddAnimation("arma3", new[] { sprites[4] }); _animator.AddAnimation("recarga", new[] { sprites[5] }); _circleCollider = Entity.AddComponent(new CircleCollider(15)); _mover = Entity.AddComponent(new Mover()); Controles(); _arma = new Arma(Entity); }
public override void OnAddedToScene() { base.OnAddedToScene(); var texture = Scene.Content.LoadTexture(texturePath); var sprites = Sprite.SpritesFromAtlas(texture, 81, 60); var animator = new SpriteAnimator(); animator.AddAnimation("Walk", 6, sprites.ToArray()); animator.RenderLayer = Constants.Layer_NPC; animator.Play("Walk"); this.animator = AddComponent(animator); AddComponent(new CivilianComponent()); AddComponent(new HomingTargetComponent()); this.mover = AddComponent(new Mover()); AddComponent(new CircleCollider(10) { PhysicsLayer = (int)Constants.PhysicsLayers.NPC }); }
public static EntityBuilder <Torch> Torch(Color?torchColor = null) { // Add sprite with animation var propAtlas = Core.Content.Load <Texture2D>(Content.Textures.Tileset_props); var propAtlasNormal = Core.Content.Load <Texture2D>(Content.Textures.Tileset_props_normal); var animation = new SpriteAnimator() .SetRenderLayer(Constants.RenderLayerProps) .SetMaterial(new DeferredSpriteMaterial(propAtlasNormal)) as SpriteAnimator; var subTextures = Sprite.SpritesFromAtlas(propAtlas, 8, 8); animation.AddAnimation(nameof(TorchAnimation.Flickering), new SpriteAnimation(new Sprite[] { subTextures[0], subTextures[1] }, 4)); animation.Play(nameof(TorchAnimation.Flickering)); // Add light effect var light = new PointLight(torchColor ?? Entities.Torch.BaseColor) .SetRadius(Entities.Torch.BaseRadius) .SetZPosition(3); light.RenderLayer = Constants.RenderLayerLight; var torch = new EntityBuilder <Torch>() .With(animation) .With(light); if (torchColor.HasValue) { torch = torch.With(t => t.Color = torchColor.Value); } return(torch); }
public override void OnAddedToEntity() { var texture = Entity.Scene.Content.LoadTexture(Content.Platformer.Caveman); var sprites = Sprite.SpritesFromAtlas(texture, 32, 32); _boxCollider = Entity.GetComponent <BoxCollider>(); _mover = Entity.GetComponent <TiledMapMover>(); _animator = Entity.AddComponent(new SpriteAnimator(sprites[0])); // the TiledMapMover does not call ITriggerListener Methods on collision. // To achieve ITriggerListener calling, this ColliderTriggerHelper can be used. // See the Update() function below, to see how this helper can be used. _triggerHelper = new ColliderTriggerHelper(Entity); // extract the animations from the atlas. they are setup in rows with 8 columns _animator.AddAnimation("Walk", new[] { sprites[0], sprites[1], sprites[2], sprites[3], sprites[4], sprites[5] }); _animator.AddAnimation("Run", new[] { sprites[8 + 0], sprites[8 + 1], sprites[8 + 2], sprites[8 + 3], sprites[8 + 4], sprites[8 + 5], sprites[8 + 6] }); _animator.AddAnimation("Idle", new[] { sprites[16] }); _animator.AddAnimation("Attack", new[] { sprites[24 + 0], sprites[24 + 1], sprites[24 + 2], sprites[24 + 3] }); _animator.AddAnimation("Death", new[] { sprites[40 + 0], sprites[40 + 1], sprites[40 + 2], sprites[40 + 3] }); _animator.AddAnimation("Falling", new[] { sprites[48] }); _animator.AddAnimation("Hurt", new[] { sprites[64], sprites[64 + 1] }); _animator.AddAnimation("Jumping", new[] { sprites[72 + 0], sprites[72 + 1], sprites[72 + 2], sprites[72 + 3] }); SetupInput(); }
public AvatarSpriteController(SpriteAnimator spriteAnimator) : base(spriteAnimator) { Texture2D texture = Core.Content.Load <Texture2D>("Objects/Characters/avatar_spritesheet"); List <Sprite> sprites = Sprite.SpritesFromAtlas( texture, SpriteSize.X, SpriteSize.Y); SpriteAnimator.AddAnimation(WalkForwardAnimation, new[] { sprites[0], sprites[1], sprites[2], }); SpriteAnimator.AddAnimation(IdleForwardAnimation, new[] { sprites[1] }); SpriteAnimator.AddAnimation(WalkSideAnimation, new[] { sprites[3], sprites[4], sprites[5] }); SpriteAnimator.AddAnimation(IdleSideAnimation, new[] { sprites[4] }); SpriteAnimator.AddAnimation(WalkBackwardAnimation, new[] { sprites[6], sprites[7], sprites[8] }); SpriteAnimator.AddAnimation(IdleBackwardAnimation, new[] { sprites[7] }); SpriteAnimator.AddAnimation(AttackForwardAnimation, new[] { sprites[36], sprites[37], sprites[38], sprites[39], sprites[40] }); SpriteAnimator.AddAnimation(AttackBackwardAnimation, new[] { sprites[7] }); SpriteAnimator.AddAnimation(AttackSideAnimation, new[] { sprites[48], sprites[49], sprites[50], sprites[51], sprites[52] }); }
public override void OnAddedToEntity() { var texture = Entity.Scene.Content.LoadTexture("Content/Tilesets/caveman.png"); var sprites = Sprite.SpritesFromAtlas(texture, 32, 32); _camera = Entity.Scene.Camera; _boxCollider = Entity.GetComponent <BoxCollider>(); _mover = Entity.GetComponent <TiledMapMover>(); _animator = Entity.AddComponent(new SpriteAnimator(sprites[0])); // extract the animations from the atlas. they are setup in rows with 8 columns _animator.AddAnimation("Walk", new[] { sprites[0], sprites[1], sprites[2], sprites[3], sprites[4], sprites[5] }); _animator.AddAnimation("Run", new[] { sprites[8 + 0], sprites[8 + 1], sprites[8 + 2], sprites[8 + 3], sprites[8 + 4], sprites[8 + 5], sprites[8 + 6] }); _animator.AddAnimation("Idle", new[] { sprites[16] }); _animator.AddAnimation("Attack", new[] { sprites[24 + 0], sprites[24 + 1], sprites[24 + 2], sprites[24 + 3] }); _animator.AddAnimation("Death", new[] { sprites[40 + 0], sprites[40 + 1], sprites[40 + 2], sprites[40 + 3] }); _animator.AddAnimation("Falling", new[] { sprites[48] }); _animator.AddAnimation("Hurt", new[] { sprites[64], sprites[64 + 1] }); _animator.AddAnimation("Jumping", new[] { sprites[72 + 0], sprites[72 + 1], sprites[72 + 2], sprites[72 + 3] }); SetupInput(); }
private void Awake() { m_facing = GetComponent <Facing>(); m_animator = GetComponent <SpriteAnimator>(); m_mover = GetComponent <Mover>(); if (m_horizontalDupeMode == HorizontalDupeMode.FlipEastFromWest) { m_animationEast = m_animationWest; m_animationNorthEast = m_animationNorthWest; m_animationSouthEast = m_animationSouthWest; } else if (m_horizontalDupeMode == HorizontalDupeMode.FlipEastFromWest) { m_animationWest = m_animationEast; m_animationNorthWest = m_animationNorthEast; m_animationSouthWest = m_animationSouthEast; } if (m_verticalDupeMode == VerticalDupeMode.FlipNorthFromSouth) { m_animationNorth = m_animationSouth; m_animationNorthEast = m_animationSouthEast; m_animationNorthWest = m_animationSouthWest; } else if (m_verticalDupeMode == VerticalDupeMode.FlipSouthFromNorth) { m_animationSouth = m_animationNorth; m_animationSouthEast = m_animationNorthEast; m_animationSouthWest = m_animationNorthWest; } if (m_animationEast.Count == 0) { Debug.LogErrorFormat("{0} has no move east animation", gameObject); } if (m_animationNorth.Count == 0) { Debug.LogErrorFormat("{0} has no move north animation", gameObject); } if (m_animationSouth.Count == 0) { Debug.LogErrorFormat("{0} has no move south animation", gameObject); } if (m_animationWest.Count == 0) { Debug.LogErrorFormat("{0} has no move west animation", gameObject); } var flipVecHorizontal = new Vector2(-1.0f, 1.0f); var flipVecVertical = new Vector2(1.0f, -1.0f); var east = new SpriteAnimator.SpriteAnimation() { Name = Facing.Direction.East.ToString(), FlipVector = m_horizontalDupeMode == HorizontalDupeMode.FlipEastFromWest ? flipVecHorizontal : Vector2.one, SpriteList = m_animationEast, Framerate = m_framerate }; m_animator.AddAnimation(east); var north = new SpriteAnimator.SpriteAnimation() { Name = Facing.Direction.North.ToString(), SpriteList = m_animationNorth, FlipVector = m_verticalDupeMode == VerticalDupeMode.FlipNorthFromSouth ? flipVecVertical : Vector2.one, Framerate = m_framerate }; m_animator.AddAnimation(north); var south = new SpriteAnimator.SpriteAnimation() { Name = Facing.Direction.South.ToString(), SpriteList = m_animationSouth, FlipVector = m_verticalDupeMode == VerticalDupeMode.FlipSouthFromNorth ? flipVecVertical : Vector2.one, Framerate = m_framerate }; m_animator.AddAnimation(south); var west = new SpriteAnimator.SpriteAnimation() { Name = Facing.Direction.West.ToString(), SpriteList = m_animationWest, FlipVector = m_horizontalDupeMode == HorizontalDupeMode.FlipWestFromEast ? flipVecHorizontal : Vector2.one, Framerate = m_framerate }; m_animator.AddAnimation(west); UpdateAnimation(); }
public override void OnAddedToEntity() { #region Load up texture atlas... //Load up character texture atlas var idleTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroIdle); var runTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroRun); var attackTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroAttack); var jumpTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroJump); var fallTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroFall); var idleSprite = Sprite.SpritesFromAtlas(idleTexture, 50, 37); var runSprite = Sprite.SpritesFromAtlas(runTexture, 50, 37); var attackSprite = Sprite.SpritesFromAtlas(attackTexture, 50, 37); var jumpSprite = Sprite.SpritesFromAtlas(jumpTexture, 50, 37); var fallSprite = Sprite.SpritesFromAtlas(fallTexture, 50, 37); #endregion Load up texture atlas... #region add componentents... //Movement component var map = Entity.Scene as SandBoxScene; Mover = Entity.AddComponent(new TiledMapMover(map.TiledMap.GetLayer <TmxLayer>("main"))); //animator component Animator = Entity.AddComponent <SpriteAnimator>(); //Set up collider Collider = Entity.AddComponent <BoxCollider>(); Collider.Width = 16; Collider.Height = 30; Collider.SetLocalOffset(new Vector2(0, 3)); Flags.SetFlagExclusive(ref Collider.CollidesWithLayers, 1); Flags.SetFlagExclusive(ref Collider.PhysicsLayer, 1); //CollisionListener CollisionListener = Entity.AddComponent <CollisionListener>(); //SetType Type = Entity.AddComponent <TypeComponent>(); Type.SetType(EntityType.PLAYER); //Set up StateMachine StateMachine = Entity.AddComponent(new StateMachine()); StateMachine.AddState(STATES.PLAYER_FREE, new PlayerPlatformerStateFree(this)); StateMachine.AddState(STATES.PLAYER_ATTACK, new PlayerStateAttack(this)); StateMachine.CurrentState = STATES.PLAYER_FREE; //Set up Camera var camera = new FollowCamera(Entity); camera.MapLockEnabled = true; Entity.AddComponent(camera); var renderer = new DefaultRenderer(camera: camera.Camera); Entity.Scene.AddRenderer(renderer); //camera.Camera.Position = Entity.Transform.Position; camera.MapSize = new Vector2(1280, 0); camera.FollowLerp = .3f; #endregion add componentents... #region Animations... Animator.AddAnimation("IdleSheathed", 3.5f, new[] { idleSprite[0], idleSprite[1], idleSprite[2], idleSprite[3] }); Animator.AddAnimation("IdleUnSheathed", 3.5f, new[] { idleSprite[4], idleSprite[5], idleSprite[6], idleSprite[7] }); Animator.AddAnimation("RunSheathed", 7.5f, new[] { runSprite[0], runSprite[1], runSprite[2], runSprite[3], runSprite[4], runSprite[5] }); Animator.AddAnimation("RunUnSheathed", 7.5f, new[] { runSprite[6], runSprite[7], runSprite[8], runSprite[9], runSprite[10], runSprite[11] }); Animator.AddAnimation("Attack0", 12, new[] { attackSprite[0], attackSprite[1], attackSprite[2], attackSprite[3], attackSprite[4], attackSprite[5], }); Animator.AddAnimation("Attack1", 12, new[] { attackSprite[6], attackSprite[7], attackSprite[8], attackSprite[9], attackSprite[10] }); Animator.AddAnimation("Attack2", 12, new[] { attackSprite[11], attackSprite[12], attackSprite[13], attackSprite[14], attackSprite[15], attackSprite[16] }); Animator.AddAnimation("Jump", 15, new[] { //jumpSprite[0], //jumpSprite[1], jumpSprite[2], jumpSprite[3] }); Animator.AddAnimation("Fall", 8, new[] { fallSprite[0], fallSprite[1] }); #endregion Animations... //Set up Input SetupInput(); base.OnAddedToEntity(); }