public SpriteAnimation Clone() { SpriteAnimation clone = new SpriteAnimation(); clone.name = name; clone.frames = frames; clone.times = times; return clone; }
void Start() { spriteAnimation = GetComponent<SpriteAnimation>(); if (spriteAnimation == null) throw new UnityException("SpriteAnimation Exception - failed to find SpriteAnimation attached to " + gameObject.name + "."); // This should NEVER arise, but just in case... door = null; // just to be sure that this will work }
/// <summary> /// Registers the icon with the specified name. /// </summary> /// <param name="name">The name of the icon to register.</param> /// <param name="icon">The icon to register.</param> /// <param name="height">The width to which to scale the icon, or null to preserve the sprite's original width.</param> /// <param name="width">The height to which to scale the icon, or null to preserve the sprite's original height.</param> public void RegisterIcon(String name, SpriteAnimation icon, Int32? width = null, Int32? height = null) { Contract.RequireNotEmpty(name, "name"); Contract.Require(icon, "icon"); registeredIcons.Add(name, new TextIconInfo(icon, width, height)); }
public void BeginAnimation(SpriteAnimation sprite) { CurrentSprite = sprite; _isPlaying = true; _columns = sprite.Columns; _rows = sprite.Rows; _framesPerSecond = sprite.FPS; _playOnce = !CurrentSprite.Loop; Material newMaterial = renderer.sharedMaterial; // First check our material instance, if we already have a material instance // and we want to create a new one, we need to clean up the old one if (_hasMaterialInstance) Object.Destroy(renderer.sharedMaterial); // create the new material _materialInstance = new Material(newMaterial); _materialInstance.mainTexture = CurrentSprite.texture; // Assign it to the renderer renderer.sharedMaterial = _materialInstance; // Set the flag _hasMaterialInstance = true; // We need to recalc the texture size (since different material = possible different texture) CalcTextureSize(); // Assign the new texture size renderer.sharedMaterial.SetTextureScale("_MainTex", _textureSize); Play(); }
public TransformationInfo(SpriteAnimation.TransformationType transformationType) { Transformation = transformationType; NormalEasing = EZAnimation.EASING_TYPE.Linear; ReverseEasing = EZAnimation.EASING_TYPE.Linear; TransformationKeyList = new List<TransformationKeyInfo>(); }
// Use this for initialization void Start() { spriteAnimation = GetComponent<SpriteAnimation>(); spriteRenderer = GetComponent<SpriteRenderer>(); updateHandler = PreUpdateHandler; //register a function to handler the animation evaluate spriteAnimation.AddComponentUpdateHandler( SpriteAnimationComponentUpdateType.PreUpdateComponent, updateHandler); }
public BaddieRobotCrawlerShooter(Scene scene, double x, double y) : base(scene.Stage, x, y, Texture.Get("sprite_robot_1")) { AnimationIdle = new SpriteAnimation(Texture, 200, true, false, new string[] { "stationary" }); AnimationCrawl = new SpriteAnimation(Texture, 200, true, false, new string[] { "crawl_0", "crawl_1", "crawl_2", "crawl_3" }); AnimationArm = new SpriteAnimation(Texture, 200, false, false, new string[] { "arm_0", "arm_1", "arm_2" }); AnimationArmed = new SpriteAnimation(Texture, 200, true, false, new string[] { "armed" }); AnimationDisarm = new SpriteAnimation(Texture, 200, false, false, new string[] { "disarm_0", "disarm_1", "disarm_2" }); AnimationFiring = new SpriteAnimation(Texture, 75, true, false, new string[] { "firing_0", "firing_1", "firing_2", "firing_3", "firing_4" }); StartAnimation(AnimationFiring); }
// Use this for initialization void Start() { //Get SpriteAnimation for GameObject spriteAnimation = GetComponent<SpriteAnimation>(); spriteAnimation["Mummy_Attack"].layer = 1; spriteAnimation["Mummy_Attack"].AddMixingComponent( "/root/hip/body", true); spriteAnimation["Mummy_Attack"].enabled = true; spriteAnimation["Mummy_Walk"].enabled = true; }
public void OnHealthChanged(object sender, HealthChangedEventArgs e) { int region_idx = (Player.HealthMax - e.HealthWas); // Hard-coded int next_idx = region_idx + 1; // Hard-coded if (e.HealthWas != e.HealthNow) { int step = e.HealthWas > e.HealthNow ? 6 : -6; _AnimationCurrent = new SpriteAnimation(Texture, 100, region_idx, region_idx + step, region_idx + 2 * step, next_idx); _AnimationFrameIndex = 0; _FrameTimer.Restart (); } }
public void SetLoop(object loop_me) { Sound sound = Sound.Get (loop_me); if (_AnimationCurrent != null) { if(_AnimationCurrent.Sound != null) AnimationCurrent.Sound.Stop(); } var animation = new SpriteAnimation(Texture, (int)(1000.0 * sound.Duration), true, false, Texture.DefaultRegionIndex); animation.Sound = sound; PlayAnimation(animation); }
//if a component in collusion list, change its color. void OnUpdateAnimation(SpriteAnimation ani) { //if mouse hover on a component, then change its color. if (lastHoverSprite != null ) { lastHoverSprite.color = Color.red; } //if mouse hover on a component, then change its color. foreach( SpriteTransform sprTran in collisionComponents) { sprTran.color = Color.green; } }
// Use this for initialization void Awake() { //get component reference spriteRenderer = GetComponent<SpriteRenderer>(); spriteAnimation = GetComponent<SpriteAnimation>(); controller = GetComponent<CharacterController>(); behaviourController = GetComponent<BehaviourControllerHolder>(); //random init move direction moveDirection = Random.Range(0f, 1f) > 0.5f ? -1 : 1; //face to move direction UpdateFaceTo(); }
// Set a current animation as the active animation. public SpriteAnimation setAnimation(SpriteAnimation anim) { if (anim != null) { currentAnimation = anim; position = 0; return anim; } else { Debug.LogError("ERROR: SpriteAnimator: Given animation docould not be found"); return null; } }
public UIButton(Scene scene, double x, double y, SpriteBase.SpriteFrame free, SpriteBase.SpriteFrame selected, UIElementGroup grp) : base(scene.HUD, x, y, free.Texture) { _Group = grp; _Group.Add(this); _ToFree = new SpriteAnimation(false, false, free); _ToSelected = new SpriteAnimation(false, false, selected); Refresh += (sender, e) => { var animation = this == _Group.ElementFocused ? _ToSelected : _ToFree; _AnimationFrameIndex = _AnimationCurrent == animation ? _AnimationFrameIndex : animation.FrameCount - _AnimationFrameIndex - 1; _AnimationCurrent = animation; }; OnRefresh(this, new EventArgs()); }
// PreUpdateHandler is called bone transformed in bone local space by SpriteAnimation void PreUpdateHandler( SpriteAnimation ani ) { //move the root in circle SpriteTransform root = spriteRenderer.GetSpriteTransform("/root"); if ( root != null ) { root.position = Quaternion.Euler( 0f, 0f, t) * (Vector3.right * 100f) ; t += 60f * Time.deltaTime; } //make the bone lookat target SpriteTransform bone = spriteRenderer.GetSpriteTransform("/root/node"); if ( bone != null ) bone.LookAt( transform.InverseTransformPoint(target.position)); }
public BulletCollisionParticle(Scene scene, double x, double y) : base(scene.Stage, x, y, Texture.Get("sprite_bullet_collision_particle")) { Hit = new SpriteAnimation(Texture, 10, false, "f1", "f2", "f3", "f4"); _AnimationNext = new Lazy<SpriteAnimation>(() => { Program.MainGame.AddUpdateEventHandler(this, (sender, e) => { RenderSet.Remove (this); this.Dispose(); return true; }); return null; }); PlayAnimation(Hit); }
void OnGUI() { if (ani == null || ani.name == "") { ani = SpriteAnimations.Get(skin); if (ani == null) { return; } } GUI.depth = depth; Rect brush = area; if (lockWidthToHeight) { brush = area.MiddleCenter(area.height/area.width, 1); } GUI.DrawTexture(brush, ani.GetImageNormalized(val)); }
// Use this for initialization void Start() { //Get SpriteAnimation for GameObject spriteAnimation = GetComponent<SpriteAnimation>(); List<string> tmp = new List<string>(); //Get all clips assigned in SpriteAnimation SpriteAnimationClip[] clips = SpriteAnimationUtility.GetAnimationClips( spriteAnimation ); foreach( SpriteAnimationClip _clip in clips) { tmp.Add( _clip.name); } spriteAnimation["Mummy_Damage"].layer = 1; animationNames = tmp.ToArray(); }
public BulletCollisionParticle(Scene scene, double x, double y) : base(scene.Stage, x, y, Texture.Get("sprite_bullet_collision_particle")) { Hit = new SpriteAnimation(Texture, 10, false, "f1", "f2", "f3", "f4"); Hit.Sound = Sound.Get ("sfx_bullet_impact"); WeakReference game_wr = new WeakReference(Set.Scene.Game); WeakReference render_set_wr = new WeakReference(Set); _AnimationNext = new Lazy<SpriteAnimation>(() => { ((PositronGame)game_wr.Target).AddUpdateEventHandler(this, (sender, e) => { ((RenderSet)render_set_wr.Target).Remove (this); this.Dispose(); return true; }); return null; }); PlayAnimation(Hit); }
// Use this for initialization void Start() { //Get SpriteAnimation for GameObject spriteAnimation = GetComponent<SpriteAnimation>(); List<string> tmp = new List<string>(); //Get all clips assigned in SpriteAnimation SpriteAnimationClip[] clips = SpriteAnimationUtility.GetAnimationClips( spriteAnimation ); foreach( SpriteAnimationClip clip in clips) { tmp.Add( clip.name); //change the wrapmode of clip to once, because if play a looping clip, you can not waiting it complete. spriteAnimation[clip.name].wrapMode = WrapMode.Once; } animationNames = tmp.ToArray(); }
public SpriteBase(RenderSet render_set, double x, double y, double scalex, double scaley, Texture texture) : base(render_set) { // Size will scale _Texture width and height _Color = Color.White; _Scale.X = scalex; _Scale.Y = scaley; _TileX = 1.0; _TileY = 1.0; _AnimationFrameIndex = 0; _FrameTimer = new Stopwatch(); _AnimationDefault = _AnimationCurrent = new SpriteAnimation(texture, 0); //_FrameStatic = _AnimationDefault.Frames[0]; // Position for world objects is handled differently if(!(this is IWorldObject)) Corner = new Vector3d(x, y, 0.0); }
// Use this for initialization void Start() { //Get component reference spriteAnimation = GetComponent<SpriteAnimation>(); spriteRenderer = GetComponent<SpriteRenderer>(); //set gameobject position randomly. transform.position = new Vector3( Random.Range(0, Screen.width), Random.Range(0, Screen.height * 0.7f ), 0); //set gameobject depth randomly. spriteRenderer.depth = Random.Range(0, 512); //Get all clips in SpriteAnimation Component, and random select one to play. List<string> tmp = new List<string>(); SpriteAnimationClip[] clips = SpriteAnimationUtility.GetAnimationClips( spriteAnimation ); foreach( SpriteAnimationClip clip in clips) { tmp.Add( clip.name); } int idx = Random.Range(0, tmp.Count); string name = tmp[ idx ]; spriteAnimation.Play( name ); SpriteAnimationState state = spriteAnimation[ name ]; state.wrapMode = WrapMode.Loop; //set move step randomly. stepX = Random.Range(50, 250); stepY = Random.Range(50, 250); //Hold a Transform reference _transform = transform; }
public void Initialize( GraphicsDevice GraphicsDevice ) { // fetch all Actions & build SpriteAnimations from it for( int a = 0; a < mRagnarokAnimation.Actions.Count; a++ ) { mAnimation[ a ] = new SpriteAnimation(); for( int f = 0; f < mRagnarokAnimation.Actions[ a ].Frames.Count; f++ ) { SpriteAnimationFrame frame = new SpriteAnimationFrame(); for( int i = 0; i < mRagnarokAnimation.Actions[ a ].Frames[ f ].Images.Count; i++ ) { RagnarokAnimationActionFrameImage roImg = mRagnarokAnimation.Actions[ a ].Frames[ f ].Images[ i ]; SpriteAnimationFrameImage img = new SpriteAnimationFrameImage(); img.Size = new Point( (int)( roImg.Width * roImg.ScaleX ), (int)( roImg.Height * roImg.ScaleY ) ); img.Position = new Point( roImg.X, roImg.Y ); img.Rotation = roImg.Rotation; img.Texture = mRagnarokAnimation.Images[ roImg.Number ].BuildTexture2D( mRagnarokAnimation.Palette, GraphicsDevice ); img.Color = Color.White; img.Mirror = ( roImg.Mirror ? SpriteEffects.FlipHorizontally : SpriteEffects.None ); frame.Images.Add( img ); } mAnimation[ a ].Frames.Add( frame ); } } }
/// <summary> /// Loads a sprite. /// </summary> /// <param name="spriteName">Name of the sprite.</param> /// <returns>A new <see cref="Sprite"/> instance.</returns> private Sprite LoadSprite(string spriteName) { if (string.IsNullOrEmpty(spriteName)) { throw new ArgumentException(Strings.ResourceNameRequired, nameof(spriteName)); } // load the sprite definition file var filePath = Path.Combine(GetResourcePath <Sprite>(), spriteName + ".txt"); var spriteData = File.ReadAllLines(filePath); var sequences = LoadAnimationSequences(spriteName); // create a new sprite instance var sprite = new Sprite(); sprite.Name = spriteName; var animationFrames = new Dictionary <string, List <SpriteAnimationFrame> >(); List <SpriteAnimationFrame> currentFrameList; // move through each of the frame definitions, and create the animations var i = 1; foreach (var line in spriteData) { var tokens = line.Split(' '); if (tokens.Length != 6) { TraceSource.TraceEvent(TraceEventType.Warning, 0, Strings.SpriteDefinitionBadTokenCount, filePath, i); continue; } var splitName = tokens[0].Split('_'); var animationName = splitName[1]; var animationFrame = Int32.Parse(splitName[2]); var rect = new Int32Rect( Int32.Parse(tokens[2]), Int32.Parse(tokens[3]), Int32.Parse(tokens[4]), Int32.Parse(tokens[5])); if (!animationFrames.TryGetValue(animationName, out currentFrameList)) { currentFrameList = new List <SpriteAnimationFrame>(); animationFrames.Add(animationName, currentFrameList); } currentFrameList.Add(new SpriteAnimationFrame(animationFrame, rect)); i++; } // write the animations to the sprite var animations = new List <SpriteAnimation>(); var animId = 0; foreach (var animation in animationFrames.Keys) { var anim = new SpriteAnimation { Name = animation, Id = animId++, Frames = animationFrames[animation].OrderBy(f => f.FrameNumber).ToArray(), Sequence = sequences[animation] }; animations.Add(anim); } sprite.Animations = animations.ToArray(); return(sprite); }
public void PlaySpriteAnimation(SpriteAnimation spriteAnimation) { animationPlayer.Play(spriteAnimation); }
private void button2_Click(object sender, RoutedEventArgs e) { SpriteDescriptor sd = new SpriteDescriptor() { ResourceType = ResourceType.Pictures }; var izettaPoint = SCamera2D.GetScreenCoordination(4, 8); var finePoint = SCamera2D.GetScreenCoordination(4, 11); var zoiPoint = SCamera2D.GetScreenCoordination(4, 24); var rm = ResourceManager.GetInstance(); var izetta = rm.GetPicture("伊泽塔1.png", new Int32Rect(-1, 0, 0, 0)); Image img1 = new Image(); img1.Source = izetta.SpriteBitmapImage; img1.Width = izetta.SpriteBitmapImage.PixelWidth; img1.Height = izetta.SpriteBitmapImage.PixelHeight; izetta.DisplayBinding = img1; izetta.AnimationElement = img1; var izettad = (SpriteDescriptor)sd.Clone(); izettad.ToScaleX = izettad.ToScaleY = 0.4; izetta.Descriptor = izettad; izetta.Descriptor.X = izettaPoint.X - izetta.SpriteBitmapImage.PixelWidth / 2.0; izetta.Descriptor.Y = izettaPoint.Y - izetta.SpriteBitmapImage.PixelHeight / 2.0; //Canvas.SetLeft(img1, 150 - izetta.SpriteBitmapImage.PixelWidth / 2.0); Canvas.SetLeft(img1, izettaPoint.X - izetta.SpriteBitmapImage.PixelWidth / 2.0); Canvas.SetTop(img1, izettaPoint.Y - izetta.SpriteBitmapImage.PixelHeight / 2.0); //Canvas.SetTop(img1, 630 - izetta.SpriteBitmapImage.PixelHeight / 2.0); Canvas.SetZIndex(img1, 50); this.BO_Cstand_Canvas.Children.Add(img1); izetta.InitAnimationRenderTransform(); SpriteAnimation.ScaleToAnimation(izetta, TimeSpan.FromMilliseconds(0), 0.4, 0.4, 0, 0); var fine = rm.GetPicture("公主1.png", new Int32Rect(-1, 0, 0, 0)); Image img2 = new Image(); img2.Source = fine.SpriteBitmapImage; img2.Width = fine.SpriteBitmapImage.PixelWidth; img2.Height = fine.SpriteBitmapImage.PixelHeight; fine.DisplayBinding = img2; fine.AnimationElement = img2; var fined = (SpriteDescriptor)sd.Clone(); fined.ToScaleX = fined.ToScaleY = 0.5; fine.Descriptor = fined; fine.Descriptor.X = finePoint.X - fine.SpriteBitmapImage.PixelWidth / 2.0; fine.Descriptor.Y = finePoint.Y + 100 - fine.SpriteBitmapImage.PixelHeight / 2.0; //Canvas.SetLeft(img2, 400 - fine.SpriteBitmapImage.PixelWidth / 2.0); //Canvas.SetTop(img2, 730 - fine.SpriteBitmapImage.PixelHeight / 2.0); Canvas.SetLeft(img2, finePoint.X - fine.SpriteBitmapImage.PixelWidth / 2.0); Canvas.SetTop(img2, finePoint.Y + 100 - fine.SpriteBitmapImage.PixelHeight / 2.0); Canvas.SetZIndex(img2, 50); this.BO_Cstand_Canvas.Children.Add(img2); fine.InitAnimationRenderTransform(); SpriteAnimation.ScaleToAnimation(fine, TimeSpan.FromMilliseconds(0), 0.5, 0.5, 0, 0); var mt = rm.GetPicture("Zoithyt-4-2.png", new Int32Rect(-1, 0, 0, 0)); Image img4 = new Image(); img4.Source = mt.SpriteBitmapImage; img4.Width = mt.SpriteBitmapImage.PixelWidth; img4.Height = mt.SpriteBitmapImage.PixelHeight; mt.DisplayBinding = img4; mt.AnimationElement = img4; var zoid = (SpriteDescriptor)sd.Clone(); zoid.ToScaleX = zoid.ToScaleY = 0.43; mt.Descriptor = zoid; mt.Descriptor.X = zoiPoint.X - mt.SpriteBitmapImage.PixelWidth / 2.0; mt.Descriptor.Y = zoiPoint.Y - mt.SpriteBitmapImage.PixelHeight / 2.0; Canvas.SetLeft(img4, zoiPoint.X - mt.SpriteBitmapImage.PixelWidth / 2.0); Canvas.SetTop(img4, zoiPoint.Y - mt.SpriteBitmapImage.PixelHeight / 2.0); Canvas.SetZIndex(img4, 50); this.BO_Cstand_Canvas.Children.Add(img4); mt.InitAnimationRenderTransform(); SpriteAnimation.ScaleToAnimation(mt, TimeSpan.FromMilliseconds(0), 0.43, 0.43, 0, 0); var bgg = rm.GetPicture("bg_school.jpg", new Int32Rect(-1, 0, 0, 0)); Image img3 = new Image(); img3.Source = bgg.SpriteBitmapImage; img3.Width = bgg.SpriteBitmapImage.PixelWidth; img3.Height = bgg.SpriteBitmapImage.PixelHeight; bgg.DisplayBinding = img3; bgg.AnimationElement = img3; bgg.Descriptor = (SpriteDescriptor)sd.Clone(); bgg.Descriptor.X = GlobalConfigContext.GAME_WINDOW_WIDTH / 2.0; bgg.Descriptor.Y = GlobalConfigContext.GAME_WINDOW_HEIGHT / 2.0; Canvas.SetLeft(img3, bgg.Descriptor.X - img3.Width / 2); Canvas.SetTop(img3, bgg.Descriptor.Y - img3.Height / 2); Canvas.SetZIndex(img3, 5); this.BO_Bg_Canvas.Children.Add(img3); bgg.InitAnimationRenderTransform(); //bgg.Descriptor.ToScaleX = 0.5; //bgg.Descriptor.ToScaleY = 0.5; //SpriteAnimation.ScaleAnimation(bgg, TimeSpan.Zero, 1, 0.5, 1, 0.5, 0, 0); TransformGroup aniGroup = new TransformGroup(); TranslateTransform XYTransformer = new TranslateTransform(); ScaleTransform ScaleTransformer = new ScaleTransform(); ScaleTransformer.CenterX = GlobalConfigContext.GAME_WINDOW_WIDTH / 2.0; ScaleTransformer.CenterY = GlobalConfigContext.GAME_WINDOW_HEIGHT / 2.0; RotateTransform RotateTransformer = new RotateTransform(); RotateTransformer.CenterX = GlobalConfigContext.GAME_WINDOW_WIDTH / 2.0; RotateTransformer.CenterY = GlobalConfigContext.GAME_WINDOW_HEIGHT / 2.0; CsScaleT = ScaleTransformer; aniGroup.Children.Add(XYTransformer); aniGroup.Children.Add(ScaleTransformer); aniGroup.Children.Add(RotateTransformer); this.BO_Cstand_Viewbox.RenderTransform = aniGroup; TransformGroup aniGroup2 = new TransformGroup(); TranslateTransform XYTransformer2 = new TranslateTransform(); ScaleTransform ScaleTransformer2 = new ScaleTransform(); ScaleTransformer2.CenterX = GlobalConfigContext.GAME_WINDOW_WIDTH / 2.0; ScaleTransformer2.CenterY = GlobalConfigContext.GAME_WINDOW_HEIGHT / 2.0; RotateTransform RotateTransformer2 = new RotateTransform(); RotateTransformer2.CenterX = GlobalConfigContext.GAME_WINDOW_WIDTH / 2.0; RotateTransformer2.CenterY = GlobalConfigContext.GAME_WINDOW_HEIGHT / 2.0; BgScaleT = ScaleTransformer2; aniGroup2.Children.Add(XYTransformer2); aniGroup2.Children.Add(ScaleTransformer2); aniGroup2.Children.Add(RotateTransformer2); this.BO_Bg_Viewbox.RenderTransform = aniGroup2; BgTG = aniGroup2; CsTG = aniGroup; bgg.Descriptor.ScaleX = 0.75; bgg.Descriptor.ScaleY = 0.75; BgScaleT.ScaleX = 1 * 0.75; BgScaleT.ScaleY = 1 * 0.75; }
public void SetAnimation(SpriteAnimation spriteAnimation) { animationPlayer.SetSpriteAnimation(spriteAnimation); }
// Use this for initialization void Start() { SpriteAnimation sp = this.GetComponent <SpriteAnimation>(); sp.sprites = Resources.LoadAll <Sprite>(@"Image/AlertBlock"); }
private Entity BuildEntity(EntityDescriptor entityDescriptor) { var entity = new Entity(entityDescriptor.EntityName); if (entityDescriptor.ShooterDescriptor.Active) { entity.addComponent(new BulletControllerComponent() { BulletCooldown = TimeSpan.FromSeconds(entityDescriptor.ShooterDescriptor.BulletCooldownInSeconds), Direction = entityDescriptor.ShooterDescriptor.Direction, Offset = entityDescriptor.ShooterDescriptor.Offset, Speed = entityDescriptor.ShooterDescriptor.Speed }); entity.addComponent(new ShooterComponent()); } if (entityDescriptor.HiddenLifeDescriptor.Active) { entity.addComponent(new HiddenLifeComponent() { Lifes = entityDescriptor.HiddenLifeDescriptor.ExtraLifes }); entity.addComponent(new CollisionCheckComponent()); } if (entityDescriptor.DoorDescriptor.Active) { entity.addComponent(new DoorComponent() { TargetEntityName = entityDescriptor.DoorDescriptor.TargetEntityName }); } if (entityDescriptor.PeriodicVisibilityToggleDescriptor.Active) { entity.addComponent(new PeriodicVisibilityToggleComponent() { SoundEffectName = entityDescriptor.PeriodicVisibilityToggleDescriptor.SoundEffectName, TimeInvisible = entityDescriptor.PeriodicVisibilityToggleDescriptor.TimeInvisible }); } if (entityDescriptor.AnimationDescriptor.Active) { var texture = contentManager.Load <Texture2D>(entityDescriptor.TextureName); var subtextures = Subtexture.subtexturesFromAtlas(texture, entityDescriptor.AnimationDescriptor.SubtextureWidth, entityDescriptor.AnimationDescriptor.SubtextureHeight); var animatedSprite = new Sprite <int>(subtextures[0]); animatedSprite.SetRenderLayer(200); foreach (var animationFrameSet in entityDescriptor.AnimationDescriptor.AnimationFrameSets) { var animationFrames = new List <Subtexture>(); foreach (var frameIndex in animationFrameSet.Frames) { animationFrames.Add(subtextures.ElementAt(frameIndex)); } var animation = new SpriteAnimation(animationFrames) { fps = entityDescriptor.AnimationDescriptor.AnimationFramesPerSecond, loop = false }; animation.setOrigin(new Vector2(0, 0)); if (entityDescriptor.AnimationLoopDescriptor.Active && entityDescriptor.AnimationLoopDescriptor.Key == animationFrameSet.Key) { animation.loop = true; } animatedSprite.AddAnimation(animationFrameSet.Key, animation); } if (entityDescriptor.IsCollidable) { entity.addComponent(new BitPixelFieldComponent(new AnimatedSpriteWrapperFactory().Create(animatedSprite))); } if (entityDescriptor.AnimationLoopDescriptor.Active) { animatedSprite.Play(entityDescriptor.AnimationLoopDescriptor.Key); } entity.addComponent(animatedSprite); } else if (!string.IsNullOrEmpty(entityDescriptor.TextureName)) { var sprite = new Sprite(contentManager.Load <Texture2D>(entityDescriptor.TextureName)); sprite.SetRenderLayer(200); sprite.SetOrigin(new Vector2(0, 0)); if (entityDescriptor.IsCollidable) { entity.addComponent(new BitPixelFieldComponent(new AnimatedSpriteWrapperFactory().Create(sprite))); } entity.addComponent(sprite); } if (entityDescriptor.MovementDescriptor.Active) { entity.addComponent(new ScriptedMovementComponent() { SpeedInPixelsPerSecond = entityDescriptor.MovementDescriptor.Speed, Paths = entityDescriptor.MovementDescriptor.Positions }); } entity.transform.setPosition(entityDescriptor.Position); return(entity); }
/// <summary> /// Switch to the first frame of this animation and start it playing in timed mode. /// </summary> /// <param name="spriteAnimation">The animation to switch to.</param> public void StartTimedAnimation(SpriteAnimation spriteAnimation) { this.CurrentAnimation = spriteAnimation; mode = AnimationMode.Time; startTime = Time.fixedTime; }
void PlayRun() { var sheet = ((SpriteFromSheet)playerSprite.SpriteProvider).Sheet; SpriteAnimation.Play(playerSprite, sheet.FindImageIndex("run0"), sheet.FindImageIndex("run4"), AnimationRepeatMode.LoopInfinite, 12); }
public SpriteAnimatorEventInfo(SpriteAnimation animation, int frame) { this.animation = animation; this.frame = frame; }
public void TestPlay() { var spriteComp = CreateSpriteComponent(20); SpriteAnimation.Play(spriteComp, 1, 5, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0))); Assert.Equal(1, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(2, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(0.5))); Assert.Equal(2, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(9), TimeSpan.FromSeconds(9))); Assert.Equal(5, spriteComp.CurrentFrame); // check that it does not exceed last frame SpriteAnimation.Play(spriteComp, 5, 7, AnimationRepeatMode.LoopInfinite, 1); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0))); Assert.Equal(5, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3))); Assert.Equal(5, spriteComp.CurrentFrame); // check looping SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(4))); Assert.Equal(6, spriteComp.CurrentFrame); // check looping SpriteAnimation.Play(spriteComp, new[] { 9, 5, 10, 9 }, AnimationRepeatMode.LoopInfinite, 1); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(0))); Assert.Equal(9, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(5, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(10, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(9, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(9, spriteComp.CurrentFrame); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1))); Assert.Equal(5, spriteComp.CurrentFrame); // check queue reset SpriteAnimation.Queue(spriteComp, 1, 2, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 3, 4, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Play(spriteComp, 7, 8, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(4))); Assert.Equal(8, spriteComp.CurrentFrame); // check queue reset SpriteAnimation.Queue(spriteComp, 1, 2, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 3, 4, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Play(spriteComp, new[] { 7, 8 }, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(4))); Assert.Equal(8, spriteComp.CurrentFrame); // check queue reset SpriteAnimation.Play(spriteComp, 0, 0, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 1, 2, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 3, 4, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Play(spriteComp, 7, 8, AnimationRepeatMode.PlayOnce, 1, false); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10))); Assert.Equal(4, spriteComp.CurrentFrame); // check queue no reset SpriteAnimation.Play(spriteComp, 0, 0, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 1, 2, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Queue(spriteComp, 3, 4, AnimationRepeatMode.PlayOnce, 1); SpriteAnimation.Play(spriteComp, new[] { 7, 8 }, AnimationRepeatMode.PlayOnce, 1, false); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10))); Assert.Equal(4, spriteComp.CurrentFrame); // check queue no reset // check default fps speed SpriteAnimation.Play(spriteComp, 0, 15, AnimationRepeatMode.PlayOnce); SpriteAnimation.Draw(new GameTime(TimeSpan.FromSeconds(0.51), TimeSpan.FromSeconds(0.51))); Assert.Equal(15, spriteComp.CurrentFrame); // check queue no reset }
public NamedSpriteAnimation(string name, SpriteAnimation spriteAnimation) { Name = name; SpriteAnimation = spriteAnimation; }
public void ValueInit(SpriteAnimation target) { target.tp.localRotation = Quaternion.identity; }
/// <summary> /// Updates all moving entities in the game /// </summary> /// <param name="elapsedTime"> /// The time between this and the previous frame. /// </param> public void Update(float elapsedTime) { // Update all entities that have a movement component List <Player> players = new List <Player>(); foreach (Player player in _game.PlayerComponent.All) { players.Add(player); } foreach (Player player in players) { // Grab input for the player InputHelper state = InputHelper.GetInput(player.PlayerIndex); // Update the player's movement component Movement movement = _game.MovementComponent[player.EntityID]; movement.Direction = state.GetLeftDirection(); SpriteAnimation spriteAnimation = _game.SpriteAnimationComponent[player.EntityID]; if (movement.Direction.Y < 0) { spriteAnimation.CurrentAnimationRow = (int)AnimationMovementDirection.Up; } if (movement.Direction.Y > 0) { spriteAnimation.CurrentAnimationRow = (int)AnimationMovementDirection.Down; } if (movement.Direction.X < 0) { spriteAnimation.CurrentAnimationRow = (int)AnimationMovementDirection.Left; } if (movement.Direction.X > 0) { spriteAnimation.CurrentAnimationRow = (int)AnimationMovementDirection.Right; } if (movement.Direction != Vector2.Zero) { movement.Direction.Normalize(); spriteAnimation.IsPlaying = true; } else { spriteAnimation.IsPlaying = false; //spriteAnimation.CurrentFrame = 1; //TODO: idle frame } _game.SpriteAnimationComponent[spriteAnimation.EntityID] = spriteAnimation; _game.MovementComponent[player.EntityID] = movement; PlayerInfo info = _game.PlayerInfoComponent[player.EntityID]; if (state.IsPressed(Inputs.TRIGGER_WEAPON)) { info.State = PlayerState.Attacking; } else { info.State = PlayerState.Default; } _game.PlayerInfoComponent[player.EntityID] = info; if (state.IsPressed(Inputs.DISPLAY_QUEST) && !state.IsHeld(Inputs.DISPLAY_QUEST)) { _game.QuestLogSystem.displayLog = !_game.QuestLogSystem.displayLog; } //set up a system to switch skills by using the 1-9 keys if (state.IsPressed(Inputs.SELECT_HOTKEY_1)) { ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill1, player.EntityID); } else if (state.IsPressed(Inputs.SELECT_HOTKEY_2)) { ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill2, player.EntityID); } else if (state.IsPressed(Inputs.SELECT_HOTKEY_3)) { ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill3, player.EntityID); } else if (state.IsPressed(Inputs.SELECT_HOTKEY_4)) { ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill4, player.EntityID); } /*else if (state.IsPressed(Keys.D5, Buttons.DPadUp)) * ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill5, player.EntityID); * else if (state.IsPressed(Keys.D6, Buttons.DPadDown)) * ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill6, player.EntityID); * else if (state.IsPressed(Keys.D7, Buttons.DPadLeft)) * ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill7, player.EntityID); * else if (state.IsPressed(Keys.D8, Buttons.DPadRight)) * ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill8, player.EntityID); * else if (state.IsPressed(Keys.D9)) * ChangeActiveSkill(_game.PlayerInfoComponent[player.EntityID].skill9, player.EntityID); */ if (state.IsHeld(Inputs.TRIGGER_SKILL)) { uint thisPlayerKey = 0; foreach (Player p in _game.PlayerComponent.All) { if (p.PlayerIndex == PlayerIndex.One) { thisPlayerKey = p.EntityID; } } SkillType activeSkill = _game.ActiveSkillComponent[player.EntityID].activeSkill; _game.SkillSystem.UseSkill(player.PlayerRace, activeSkill, getRank(player.EntityID, activeSkill), player.EntityID); //game.SkillSystem.UseSkill(player.PlayerRace, SkillType.Invisibility, 1, thisPlayerKey); //game.SkillSystem.UseSkill(player.PlayerRace, SkillType.ThrusterRush, 1, thisPlayerKey); } } }
public void startElementLayer(Vector3 pos, Vector3 size) { GameObject gotileElementLayer = new GameObject("TileElementLayer"); gotileElementLayer.GetComponent <Transform> ().SetParent(this.transform); tileElementLayerBack = gotileElementLayer.AddComponent <SpriteRenderer> (); tileElementLayerBack.gameObject.transform.position = pos; tileElementLayerBack.gameObject.transform.localScale = new Vector2(1f, 1f); tileElementLayerBack.sortingLayerName = "TileElement"; tileElementLayerBack.sortingOrder = (int)(1000 - data.GetRealWorldPosition().y *5); tileElementLayerBack.color = new Color(1f, 1f, 1f, 1f); GameObject gotileElementLayer2 = new GameObject("TileElementLayer2"); gotileElementLayer2.GetComponent <Transform> ().SetParent(this.transform); tileElementLayerFront = gotileElementLayer2.AddComponent <SpriteRenderer> (); tileElementLayerFront.gameObject.transform.position = pos; tileElementLayerFront.gameObject.transform.localScale = new Vector2(1f, 1f); tileElementLayerFront.sortingLayerName = "TileElement"; tileElementLayerFront.color = new Color(1f, 1f, 1f, 1f); tileElementLayerFront.sortingOrder = (int)(1000 - data.GetRealWorldPosition().y *5 + 4); switch (Random.Range(1, 5)) { //Fire case case 1: elementType = ElementType.FIRE; tileElementLayerBack.gameObject.transform.position = pos + new Vector3(0.0f, +0.5f); tileElementLayerFront.gameObject.transform.position = pos + new Vector3(0.0f, -0.25f); //Animations frontAnimation = new SpriteAnimation(tileElementLayerFront); frontAnimation.LoadSprites("Tiles/Fire/front", 6); frontAnimation.RandomStart(); frontAnimation.playAnimation(); backAnimation = new SpriteAnimation(tileElementLayerBack); backAnimation.LoadSprites("Tiles/Fire/back", 6); backAnimation.RandomStart(); backAnimation.playAnimation(); //Shader int baseOffset = Random.Range(0, 20); if (GameObject.Find("Main Camera").GetComponent <GameController> () != null) { Material mat = GameObject.Find("Main Camera").GetComponent <GameController> ().fire; //tileElementLayerFront.material = mat; //tileElementLayerFront.material.SetFloat ("_RandomStart",Mathf.PI+baseOffset); } if (GameObject.Find("Main Camera").GetComponent <GameController> () != null) { Material mat = GameObject.Find("Main Camera").GetComponent <GameController> ().fire; //tileElementLayerBack.material = mat; //tileElementLayerBack.material.SetFloat ("_RandomStart",2*Mathf.PI+baseOffset); } break; //Water case case 2: elementType = ElementType.WATER; tileElementLayerFront.gameObject.transform.position = pos + new Vector3(0.0f, 0.0f); //Animations frontAnimation = new SpriteAnimation(tileElementLayerFront); frontAnimation.LoadSprites("Tiles/Water/tile_water_", 10, 26); frontAnimation.RandomStart(); frontAnimation.mode = SpriteAnimationMode.BOUNCE; frontAnimation.playAnimation(); tileElementLayerBack.gameObject.transform.position = pos + new Vector3(1.2f, 0.7f); backAnimation = new SpriteAnimation(tileElementLayerBack); backAnimation.LoadSprites("Tiles/Water/tile_water_", 10, 26); backAnimation.RandomStart(); backAnimation.mode = SpriteAnimationMode.BOUNCE; backAnimation.playAnimation(); break; //Earth case case 3: elementType = ElementType.EARTH; tileElementLayerFront.gameObject.transform.position = pos + new Vector3(0.75f, -0.25f); tileElementLayerBack.gameObject.transform.position = pos + new Vector3(-0.5f, +0.55f); tileElementLayerFront.gameObject.transform.localScale = new Vector2(0.6f, 1f); tileElementLayerBack.gameObject.transform.localScale = new Vector2(0.85f, 1.2f); //Animations frontAnimation = new SpriteAnimation(tileElementLayerFront); frontAnimation.LoadSprites("Tiles/Earth/tile_earth_", 16); frontAnimation.RandomStart(); frontAnimation.mode = SpriteAnimationMode.LOOP; frontAnimation.playAnimation(); backAnimation = new SpriteAnimation(tileElementLayerBack); backAnimation.LoadSprites("Tiles/Earth/tile_earth_", 16); backAnimation.RandomStart(); backAnimation.mode = SpriteAnimationMode.LOOP; backAnimation.playAnimation(); break; default: elementType = ElementType.NONE; break; } }
public SpriteAnimationComponent(SpriteAnimation animation, float scale, Vector2 offset) { this.Animation = animation; this.Scale = scale; this.Offset = offset; }
public override void Start() { var sprite = Entity.Get <SpriteComponent>(); SpriteAnimation.Play(sprite, 0, sprite.SpriteProvider.SpritesCount - 1, AnimationRepeatMode.LoopInfinite, 2); }
void PlayIdle() { var sheet = ((SpriteFromSheet)playerSprite.SpriteProvider).Sheet; SpriteAnimation.Play(playerSprite, sheet.FindImageIndex("idle0"), sheet.FindImageIndex("idle4"), AnimationRepeatMode.LoopInfinite, 7); }
void Start() { ani = SpriteAnimations.Get(skin); }
public override void OnInspectorGUI() { sp = target as SpriteAnimation; var serializedObject = new UnityEditor.SerializedObject(sp); serializedObject.Update(); CacheAnimationNames (); var spAutoStart = serializedObject.FindProperty ("autoStart"); var spMode = serializedObject.FindProperty ("mode"); var spAssets = serializedObject.FindProperty ("assets"); var spSpeedRatio = serializedObject.FindProperty ("speedRatio"); EditorGUILayout.PropertyField (spAutoStart); EditorGUILayout.PropertyField (spSpeedRatio, new GUIContent("Speed Ratio: ") ); EditorGUILayout.PropertyField (spMode); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(spAssets, true); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties (); cachedAnimationNames = false; CacheAnimationNames(); int newIdx = GetSelectedAnimationIdx(); if (newIdx == -1) { SetCurrentAnimation(string.Empty); } } selectedAnimationIdx = sp.currentAnimationIdx+1; //GetSelectedAnimationIdx(); int lastAnimIdx = selectedAnimationIdx; selectedAnimationIdx = EditorGUILayout.Popup ("Selected Animation: ", selectedAnimationIdx, animationNames.ToArray ()); if (selectedAnimationIdx != lastAnimIdx) { serializedObject.ApplyModifiedProperties (); //SetSelectedAnimation(); //sp.Play(selectedAnimationIdx-1); changedAnim = true; changedAnimIdx = selectedAnimationIdx; } if (sp.currentAnimationName != null) EditorGUILayout.PropertyField ( serializedObject.FindProperty("playFrom"), new GUIContent("Play from keyframe: ") ); // draw list GUILayout.Space (20); SerializedProperty animList = serializedObject.FindProperty ("list"); float nameSize = 140; if (animList.arraySize>0) { GUILayoutOption[] options = new GUILayoutOption[2]; options[0] = GUILayout.MaxWidth(265); options[1] = GUILayout.MinWidth(265); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); Rect itemRect = GUILayoutUtility.GetRect(200,18, options); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUI.Box(itemRect, new GUIContent(string.Empty)); itemRect.width = nameSize; EditorGUI.LabelField(itemRect, "Animation Name"); itemRect.xMin = itemRect.xMax; itemRect.width = 45; EditorGUI.LabelField(itemRect, "Index"); for (int i = 0; i < animList.arraySize; i++) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); itemRect = GUILayoutUtility.GetRect(200,18, options); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); itemRect.width = nameSize; GUI.Box(itemRect, new GUIContent(string.Empty)); SerializedProperty item = animList.GetArrayElementAtIndex(i); EditorGUI.LabelField(itemRect, item.FindPropertyRelative("animationName").stringValue); itemRect.xMin = itemRect.xMax; itemRect.width = 45; GUI.Box(itemRect, new GUIContent(string.Empty)); EditorGUI.LabelField(itemRect, i.ToString()); itemRect.xMin = itemRect.xMax; itemRect.width = 30; if (i>0 && GUI.Button(itemRect, "Up")) { animList.MoveArrayElement(i, i-1); if (sp.currentAnimationIdx == i) serializedObject.FindProperty("animIdx").intValue--; else if (sp.currentAnimationIdx == i-1) serializedObject.FindProperty("animIdx").intValue++; serializedObject.ApplyModifiedProperties(); return; } itemRect.xMin = itemRect.xMax; itemRect.width = 50; if (i<animList.arraySize-1 && GUI.Button(itemRect, "Down")) { animList.MoveArrayElement(i, i+1); if (sp.currentAnimationIdx == i) serializedObject.FindProperty("animIdx").intValue++; else if (sp.currentAnimationIdx == i+1) serializedObject.FindProperty("animIdx").intValue--; serializedObject.ApplyModifiedProperties(); return; } } } if (Event.current.type == EventType.Repaint && changedAnim) { changedAnim = false; sp.SetCurrentAnimation (changedAnimIdx-1); //sp.Play(changedAnimIdx-1); } if (GUI.changed) serializedObject.ApplyModifiedProperties (); }
/// <summary> /// 将系统跳转到指定的稳定状态 /// </summary> /// <param name="ssp">要演绎的状态包装</param> public static void GotoSteadyState(RollbackableSnapshot ssp) { // 停止消息循环 Director.PauseUpdateContext(); // 结束全部动画 SpriteAnimation.ClearAnimateWaitingDict(); // 检查是否需要回滚当前的并行处理和信号绑定 bool needRepara = false; if (ssp.VMRef.ESP.BindingSceneName != Director.RunMana.CallStack.SAVEP.BindingSceneName) { Director.RunMana.PauseParallel(); needRepara = true; } // 退到SSP所描述的状态 SymbolTable.GetInstance().SetDAO(ssp.sceneDao.Fork() as SceneContextDAO, ssp.globalDao.Fork() as GlobalContextDAO); ScreenManager.ResetSynObject(ssp.ScreenStateRef.Fork() as ScreenManager); Director.RunMana.ResetCallstackObject(ssp.VMRef.Fork() as StackMachine); Director.RunMana.Musics = ForkableState.DeepCopyBySerialization(ssp.MusicRef); Director.RunMana.DashingPureSa = ssp.ReactionRef.Clone(true); Director.RunMana.SemaphoreBindings = ForkableState.DeepCopyBySerialization(ssp.SemaphoreDict); Director.ScrMana = ScreenManager.GetInstance(); // 刷新主渲染器上的堆栈绑定 Director.GetInstance().RefreshMainRenderVMReference(); Director.GetInstance().GetMainRender().IsBranching = ssp.IsBranchingRefer; // 重绘整个画面 ViewManager.GetInstance().ReDraw(); // 恢复音效 UpdateRender render = Director.GetInstance().GetMainRender(); if (GlobalConfigContext.UseBassEngine) { MusicianBass.GetInstance().RePerform(Director.RunMana.Musics); } else { Musician.GetInstance().RePerform(Director.RunMana.Musics); } // 清空字符串缓冲 render.dialogPreStr = String.Empty; render.pendingDialogQueue.Clear(); // 关闭自动播放 Director.RunMana.IsAutoplaying = false; // 弹空全部等待,复现保存最后一个动作 Director.RunMana.ExitUserWait(); Interrupt reactionNtr = new Interrupt() { Type = InterruptType.LoadReaction, Detail = "Reaction for rollback", InterruptSA = ssp.ReactionRef, InterruptFuncSign = String.Empty, ReturnTarget = null, PureInterrupt = true }; // 提交中断到主调用堆栈 Director.RunMana.CallStack.Submit(reactionNtr); // 重启并行处理和信号系统 if (needRepara) { var sc = ResourceManager.GetInstance().GetScene(ssp.VMRef.EBP.BindingSceneName); Director.RunMana.ConstructParallelForRollingBack(sc); Director.RunMana.BackTraceParallel(); Director.RunMana.LastScenario = sc.Scenario; SemaphoreDispatcher.ReBinding(sc, Director.RunMana.SemaphoreBindings); } // 重启消息循环 Director.ResumeUpdateContext(); }
void Awake() { m_Transform = this.gameObject.GetComponent<Transform>(); anim = this.gameObject.GetComponent<SpriteAnimation>(); }
public void Update(GameTime gameTime) { if (immunity <= 0) { State = PlayerStates.Dying; } else { if (Constants.isJumping) { State = PlayerStates.Jumping; if (!playerAnimation.Active) { Constants.isJumping = false; State = PlayerStates.Running; jumpAnimation.Initialize(jumpTexture, new Vector2(Position.X, Position.Y - 160), runTexture.Height, jumpTexture.Height, jumpTexture.Width / runTexture.Height, 80, Color.White, scale, false); } } else { if (Constants.isBending) { State = PlayerStates.Sliding; if (!playerAnimation.Active) { Constants.isBending = false; State = PlayerStates.Running; slidingAnimation.Initialize(slideTexture, new Vector2(Position.X, Position.Y + 60), slideTexture.Height, slideTexture.Height, slideTexture.Width / slideTexture.Height, 120, Color.White, scale, false); } } else { if (Constants.isSwappingHand && hasSword) { State = PlayerStates.hasSword; if (!playerAnimation.Active) { Constants.isSwappingHand = false; State = PlayerStates.Running; swordAnimation.Initialize(swordTexture, Position, swordTexture.Height, swordTexture.Height, swordTexture.Width / swordTexture.Height, 50, Color.White, scale, false); } } else { if (Constants.isPunching) { State = PlayerStates.Punching; if (!playerAnimation.Active) { Constants.isPunching = false; State = PlayerStates.Running; punchAnimation.Initialize(punchTexture, Position, punchTexture.Height, punchTexture.Height, punchTexture.Width / punchTexture.Height, 50, Color.White, scale, false); } } } } } } switch (State) { case PlayerStates.Running: playerAnimation = runAnimation; break; case PlayerStates.Jumping: playerAnimation = jumpAnimation; break; case PlayerStates.Sliding: playerAnimation = slidingAnimation; break; case PlayerStates.hasSword: playerAnimation = swordAnimation; break; case PlayerStates.Dying: playerAnimation = dieAnimation; break; case PlayerStates.Punching: playerAnimation = punchAnimation; break; default: playerAnimation = runAnimation; break; } Position.X += speedX; runAnimation.Position.X += speedX; jumpAnimation.Position.X += speedX; slidingAnimation.Position.X += speedX; swordAnimation.Position.X += speedX; punchAnimation.Position.X += speedX; playerAnimation.Update(gameTime); //Increment Score score++; }
protected SmallGateway(RenderSet render_set, double x, double y, SharedState <bool> sync_state) : base(render_set, x, y, sync_state, Texture.Get("sprite_mini_gate")) { Open = new SpriteAnimation(Texture, 50, false, "closed", "opening_1", "opening_2", "open"); Close = new SpriteAnimation(Texture, 50, false, "open", "opening_2", "opening_1", "closed"); }
public ObjectLink(SpriteAnimation b) { me = b; back = null; }
public MenuScene(Module App) : base(App) { Background = "sta.pac"; Music = "15_MUS 15_HSC.ogg"; Position = (app.Engine.GameResolution - new Vector2(320, 200)) / 2; // face PlayerOneFace = new FaceWindow(App); PlayerOneFace.MaxFaceID = 5; PlayerOneFace.Position = new Vector2(33, 28); PlayerOneFace.Group = 3; Windows += PlayerOneFace; PlayerTwoFace = new FaceWindow(App); PlayerTwoFace.MaxFaceID = 5; PlayerTwoFace.Position = new Vector2(223, 28); PlayerTwoFace.Group = 3; Windows += PlayerTwoFace; // face slides Image image = new Image(App, "sta.ani?10-16"); image.Position = new Vector2(30, 26); image.Layer++; PlayerOneSlide = image.Background.Animation; Windows += image; image = new Image(App, "sta.ani?10-16"); image.Position = new Vector2(220, 26); image.Layer++; PlayerTwoSlide = image.Background.Animation; Windows += image; PlayerOneSlide.Speed = 10; PlayerTwoSlide.Speed = 10; PlayerOneSlide.Endless = false; PlayerOneSlide.Stop(); PlayerOneSlide.GoLastFrame(); PlayerTwoSlide.Endless = false; PlayerTwoSlide.Stop(); PlayerTwoSlide.GoLastFrame(); // buttons Button button = new Button(App); button.Position = new Vector2(131, 42); button.Image = "sta.ani?17"; button.HoverImage = "sta.ani?18"; button.Command += OnButtonStart; Windows += button; button = new Button(App); button.Position = new Vector2(131, 15); button.Image = "sta.ani?19"; button.HoverImage = "sta.ani?20"; button.Command += OnButtonLoad; Windows += button; // exit button button = new Button(App); button.Image = "gfx/menu_exit.png"; button.HoverImage = "gfx/menu_exit_hover.png"; button.Position = new Vector2(276, 163); button.Command += OnButtonExit; Windows += button; // player names PlayerOneSwitch = new NameWindow(App); PlayerOneSwitch.Position = new Vector2(15, 92); PlayerOneSwitch.Image = "sta.ani?6"; PlayerOneSwitch.DownImage = "sta.ani?7"; PlayerOneSwitch.DownCommand += OnPlayerOneDown; PlayerOneSwitch.UpCommand += OnPlayerOneUp; PlayerOneSwitch.Command += OnPlayerOneClick; PlayerOneSwitch.Font = new GuiFont(BurntimeClassic.FontName, new PixelColor(184, 184, 184)); Windows += PlayerOneSwitch; PlayerTwoSwitch = new NameWindow(App); PlayerTwoSwitch.Position = new Vector2(204, 92); PlayerTwoSwitch.Image = "sta.ani?6"; PlayerTwoSwitch.DownImage = "sta.ani?7"; PlayerTwoSwitch.DownCommand += OnPlayerTwoDown; PlayerTwoSwitch.UpCommand += OnPlayerTwoUp; PlayerTwoSwitch.Command += OnPlayerTwoClick; PlayerTwoSwitch.Font = new GuiFont(BurntimeClassic.FontName, new PixelColor(184, 184, 184)); Windows += PlayerTwoSwitch; // color Radio radio = new Radio(App); radio.Position = new Vector2(45, 121); radio.Image = "sta.ani?8"; radio.DownImage = "sta.ani?9"; radio.Mode = RadioMode.Round; radio.Group = 2; Color = radio; Windows += radio; radio = new Radio(App); radio.IsDown = true; radio.Position = new Vector2(237, 121); radio.Image = "sta.ani?8"; radio.DownImage = "sta.ani?9"; radio.Mode = RadioMode.Round; radio.Group = 2; Windows += radio; // difficulty for (int i = 0; i < 3; i++) { radio = new Radio(App); if (i == 0) { radio.IsDown = true; Difficulty = radio; } radio.Position = new Vector2(100 + 45 * i, 149); radio.Image = "sta.ani?" + (i * 2).ToString(); radio.HoverImage = "sta.ani?" + (i * 2 + 1).ToString(); radio.DownImage = "sta.ani?" + (i * 2 + 1).ToString(); radio.Group = 1; Windows += radio; } // input conversion conversionTable = new Burntime.Platform.IO.ConfigFile(); conversionTable.Open(Burntime.Platform.IO.FileSystem.GetFile("conversion_table.txt")); PlayerOneSwitch.Table = conversionTable; PlayerTwoSwitch.Table = conversionTable; }
public VisualEnemyUnit(EnemyUnit enemyUnit, SpriteAnimation spriteAnimation) { EnemyUnit = enemyUnit; MovementAnimation = spriteAnimation; }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth) { DrawSpriteAnimation(spriteAnimation, imageVariant, time, position, depth, Vector2F.Zero); }
/// <summary> /// New sprite /// </summary> /// <param name="assetName">TODO</param> /// <param name="location">Screen location</param> /// <param name="spriteRect">Spritesheet source rectangle</param> /// <param name="speed">Moving speed</param> /// <param name="scale">Scale</param> public Entity(String assetName, Vector2 location, Rectangle spriteRect, Vector2 scale) { this.assetName = assetName; this.location = location; this.sRect = spriteRect; this.scale = scale; this.ComputeDstRect(); //Default this.spriteOrigin = Vector2.Zero; this.flip = SpriteEffects.None; this.animation = null; //No animation this.IsRemovable = true; this.Size = new Vector2(spriteRect.Width, spriteRect.Height); this.hitbox = null; this.awarenessbox = null; this.Color = Color.White; IsAlive = true; Floor = null; LayerDepth = 100; }
protected BunkerFloor(Scene scene, double x, double y, Texture texture) : base(scene.Stage, x, y, texture) { _Variant = Variance.Next(Texture.Regions.Length); PlayAnimation(_AnimationDefault = new SpriteAnimation(Texture, _Variant)); }
/// <summary> /// Switch to the first frame of the specified animation and stay there. /// </summary> /// <param name="spriteAnimation">The animation to switch to</param> public void StartIdleAnimation(SpriteAnimation spriteAnimation) { this.CurrentAnimation = spriteAnimation; mode = AnimationMode.Stopped; }
void Awake() { m_Transform = this.gameObject.GetComponent <Transform>(); anim = this.gameObject.GetComponent <SpriteAnimation>(); }
public MobileSprite(Texture2D texture) { _spriteAnimation = new SpriteAnimation(texture); }
/// <summary> /// Updates all Enemies in the game /// </summary> /// <param name="elapsedTime"> /// The time between this and the previous frame. /// </param> public void Update(float elapsedTime) { List <uint> keyList = game.EnemyAIComponent.Keys.ToList <uint>(); foreach (uint id in keyList) { EnemyAI enemyAI = game.EnemyAIComponent[id]; Enemy enemy = game.EnemyComponent[id]; AIBehaviorType AIBehavior = enemyAI.AIBehaviorType; Position pos = game.PositionComponent[id]; Movement movement; if (pos.RoomID != game.CurrentRoomEid) { continue; } if (game.EnemyComponent[id].Health <= 0) { //Positions for sludge splitting Position pos1, pos2; pos1 = pos2 = pos; pos1.Center.X -= pos.Radius / 2; pos2.Center.X += pos.Radius / 2; switch (enemy.Type) { case EnemyType.Sludge5: game.EnemyFactory.CreateEnemy(EnemyType.Sludge4, pos1); game.EnemyFactory.CreateEnemy(EnemyType.Sludge4, pos2); game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; case EnemyType.Sludge4: game.EnemyFactory.CreateEnemy(EnemyType.Sludge3, pos1); game.EnemyFactory.CreateEnemy(EnemyType.Sludge3, pos2); game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; case EnemyType.Sludge3: game.EnemyFactory.CreateEnemy(EnemyType.Sludge2, pos1); game.EnemyFactory.CreateEnemy(EnemyType.Sludge2, pos2); game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; case EnemyType.Sludge2: game.EnemyFactory.CreateEnemy(EnemyType.Sludge1, pos1); game.EnemyFactory.CreateEnemy(EnemyType.Sludge1, pos2); game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; case EnemyType.Sludge1: game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; default: game.GarbagemanSystem.ScheduleVisit(id, GarbagemanSystem.ComponentType.Enemy); break; } uint eid = Entity.NextEntity(); Position effectPos = pos; effectPos.Radius = 40; effectPos.EntityID = eid; game.PositionComponent.Add(eid, effectPos); TimedEffect timedEffect = new TimedEffect() { EntityID = eid, TimeLeft = 2f, TotalDuration = 2f, }; game.TimedEffectComponent.Add(eid, timedEffect); Sprite sprite = new Sprite() { EntityID = eid, SpriteSheet = game.Content.Load <Texture2D>("Spritesheets/blood"), SpriteBounds = new Rectangle(0, 0, 80, 80), }; game.SpriteComponent.Add(eid, sprite); SpriteAnimation spriteAnimation = new SpriteAnimation() { CurrentAnimationRow = 0, CurrentFrame = 0, EntityID = eid, FramesPerSecond = 20, IsLooping = false, IsPlaying = true, TimePassed = 0f, }; game.SpriteAnimationComponent.Add(eid, spriteAnimation); } uint targetID; float dist; switch (AIBehavior) { case AIBehaviorType.DefaultMelee: updateTargeting(id); if (!enemyAI.HasTarget) { ManageAnimation(id); continue; } MoveTowardTarget(id); targetID = enemyAI.TargetID; game.SkillSystem.EnemyUseBasicMelee(id, targetID, 1, 1); ManageAnimation(id); break; case AIBehaviorType.DefaultRanged: updateTargeting(id); if (!enemyAI.HasTarget) { ManageAnimation(id); continue; } bool onCooldown = false; foreach (CoolDown cd in game.CoolDownComponent.All) { if (cd.Type == SkillType.BasicRangedAttack && cd.UserID == id) { onCooldown = true; break; } } if (onCooldown) { //wait/move random direction continue; } targetID = enemyAI.TargetID; dist = Vector2.Distance(pos.Center, game.PositionComponent[targetID].Center); movement = game.MovementComponent[id]; if (dist > 300) { MoveTowardTarget(id); } else { //movement.Direction = Vector2.Zero; //game.MovementComponent[id] = movement; //Put spritesheets here string spriteSheet; Rectangle spriteBounds; int damage; switch (enemy.Type) { case EnemyType.Sludge5: case EnemyType.Sludge4: spriteSheet = "Spritesheets/Skills/Effects/SludgeShotBig"; spriteBounds = new Rectangle(0, 0, 64, 58); damage = 2; break; case EnemyType.Sludge3: case EnemyType.Sludge2: spriteSheet = "Spritesheets/Skills/Effects/SludgeShotSmall"; spriteBounds = new Rectangle(0, 0, 16, 15); damage = 1; break; default: spriteSheet = "Spritesheets/Skills/Effects/AlienOrb"; spriteBounds = new Rectangle(0, 0, 20, 20); damage = 1; break; } game.SkillSystem.EnemyUseBasicRanged(id, targetID, damage, 3f, spriteSheet, spriteBounds); movement.Direction = new Vector2(rand.Next(20) - 10, rand.Next(20) - 10); movement.Direction = Vector2.Normalize(movement.Direction); game.MovementComponent[id] = movement; } ManageAnimation(id); break; case AIBehaviorType.CloakingRanged: updateTargeting(id); if (!enemyAI.HasTarget) { ManageAnimation(id); continue; } targetID = enemyAI.TargetID; dist = Vector2.Distance(pos.Center, game.PositionComponent[targetID].Center); bool isUsingCloak = false; foreach (Cloak cloak in game.CloakComponent.All) { if (cloak.TargetID == id) { if (cloak.TimeLeft > 2 && cloak.StartingTime - cloak.TimeLeft > 2) { isUsingCloak = true; } break; } } movement = game.MovementComponent[id]; if (!isUsingCloak) { if (dist > 300) { MoveTowardTarget(id); } else { movement.Direction = Vector2.Zero; game.MovementComponent[id] = movement; //game.SkillSystem.EnemyUseSkill(SkillType.SniperShot, id, targetID); game.SkillSystem.EnemyUseBasicRanged(id, targetID, 1, 1f, "Spritesheets/Skills/Effects/AlienOrb", new Rectangle(0, 0, 20, 20)); game.SkillSystem.EnemyUseSkill(SkillType.Cloak, id, id); } } else if (movement.Direction.Equals(Vector2.Zero)) { movement.Direction = new Vector2(rand.Next(20) - 10, rand.Next(20) - 10); movement.Direction = Vector2.Normalize(movement.Direction); game.MovementComponent[id] = movement; } ManageAnimation(id); break; case AIBehaviorType.Spider: updateTargeting(id); if (!enemyAI.HasTarget) { ManageAnimation(id); continue; } MoveTowardTarget(id); targetID = enemyAI.TargetID; dist = Vector2.Distance(pos.Center, game.PositionComponent[targetID].Center); if (dist < 50) { game.SkillSystem.EnemyUseSkill(SkillType.DamagingPull, id, targetID); game.SkillSystem.EnemyUseBasicMelee(id, targetID, 1, 1); } ManageAnimation(id); break; default: break; } } }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawSpriteAnimation(spriteAnimation, 0, time, position, depth, depthOrigin); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); AnimatedSprite spr = target as AnimatedSprite; if (spr.spriteSheet == null) { return; } GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector); spr.play = EditorGUILayout.Toggle("Play?", spr.play); GUILayout.Label("Current : "); string[] names = new string[spr.spriteAnimListInternal.Count]; int idx = 0; int current = 0; foreach (SpriteAnimation a in spr.spriteAnimListInternal) { names[idx] = a.name; if (a == spr.current) { current = idx; } ++idx; } int selec = EditorGUILayout.Popup(current, names); if (selec != current) { spr.currentName = names[selec]; } EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); EditorGUILayout.Space(); GUILayout.Label("Name", GUILayout.Width(60)); GUILayout.Label("Start", GUILayout.Width(60)); GUILayout.Label("End", GUILayout.Width(60)); GUILayout.Label("Speed", GUILayout.Width(60)); GUILayout.Label("WrapMode", GUILayout.Width(60)); GUILayout.Space(60); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); List <SpriteAnimation> toRemove = new List <SpriteAnimation>(); if (spr.spriteAnimListInternal != null) { List <SpriteAnimation> copyAnim = new List <SpriteAnimation>(spr.spriteAnimListInternal); int i = 0; foreach (SpriteAnimation anim in copyAnim) { EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); EditorGUILayout.Space(); anim.name = GUILayout.TextField(anim.name, GUILayout.Width(60)); anim.startFrame = EditorGUILayout.IntField(anim.startFrame, GUILayout.Width(60)); anim.endFrame = EditorGUILayout.IntField(anim.endFrame, GUILayout.Width(60)); anim.duration = EditorGUILayout.FloatField(anim.duration, GUILayout.Width(60)); anim.wrapMode = (WrapMode)EditorGUILayout.EnumPopup(anim.wrapMode, GUILayout.Width(60)); if (GUILayout.Button("-", GUILayout.Width(60))) { toRemove.Add(anim); } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); ++i; } foreach (SpriteAnimation a in toRemove) { copyAnim.Remove(a); } spr.spriteAnimListInternal.Clear(); spr.spriteAnimListInternal.AddRange(copyAnim); spr.RebuildAnimDictionnary(); } if (GUILayout.Button("+")) { spr.AddAnimation("NewAnim", new int[] { 0, 1 }); } SpriteAnimation addedAnim = EditorGUILayout.ObjectField("Drag or choose here an anim to add", null, typeof(SpriteAnimation), false) as SpriteAnimation; if (addedAnim != null) { spr.spriteAnimListInternal.Add(addedAnim); spr.RebuildAnimDictionnary(); } EditorGUILayout.EndVertical(); }
protected void SetAnimation(SpriteAnimation animation) { this.SpriteAnimator.AddAnimation(Tile.defaultAnimationName, animation); }
// Use this for initialization void Start() { Anim = GetComponent <SpriteAnimation>(); }