public void play(string animName, bool forced = false) { // check if we are given the same animation that is currently playing if (_currentAnim.name == animName) { if (forced) { _finishedCount = 0; _currentFrame = 0; _time = 0; // redraw element = Futile.atlasManager.GetElementWithName(_currentAnim.filename + "_" + _currentAnim.frames[0]); } return; } // find the animation with the name given, no change if not found foreach (FAnimation anim in _animations) { if (anim.name.Equals(animName, StringComparison.Ordinal)) { //Debug.Log("Playing " + anim.name); _finishedCount = 0; _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = Futile.atlasManager.GetElementWithName(_currentAnim.filename + "_" + anim.frames[0]); break; } } }
public LungLevel() { background_ = new FAnimatedSprite("Lungs_Background"); int[] breathing_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; FAnimation breathing_animation = new FAnimation("breathing", "Lungs_Background", breathing_frames, 250, true); background_.addAnimation(breathing_animation); background_.play("breathing"); AddChild(background_); dust_container_size_ = new Rect(-Futile.screen.halfWidth * 2.5f, -Futile.screen.halfHeight * 2.5f, Futile.screen.width * 2.5f, Futile.screen.height * 2.5f); dust1_ = new Dust("Dust_4", dust_container_size_); AddChild(dust1_); tubes1_ = new FSprite("Lungs_Rear"); AddChild(tubes1_); tubes2_ = new FSprite("Lungs_MidBack1"); AddChild(tubes2_); dust2_ = new Dust("Dust_3", dust_container_size_); AddChild(dust2_); tubes3_ = new FSprite("Lungs_MiddleFore"); AddChild(tubes3_); tubes4_ = new FSprite("Lungs_Fore"); AddChild(tubes4_); dust3_ = new Dust("Dust_2", dust_container_size_); AddChild(dust3_); }
public void play(string animName, bool forced = false) { // check if we are given the same animation that is currently playing if (_currentAnim.name == animName) { if (forced) { // restart at first frame _currentFrame = 0; _time = 0; // redraw element = this.GetElementWithName(_currentAnim.elementName + "_" + _currentAnim.name + "_" + _currentFrame); } return; } // find the animation with the name given, no change if not found foreach (FAnimation anim in _animations) { if (anim.name == animName) { _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = this.GetElementWithName(_currentAnim.elementName + "_" + _currentAnim.name + "_" + _currentFrame); break; } } }
public LungLevel() { background_ = new FAnimatedSprite("Lungs_Background"); int[] breathing_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; FAnimation breathing_animation = new FAnimation("breathing", "Lungs_Background", breathing_frames, 250, true); background_.addAnimation(breathing_animation); background_.play("breathing"); AddChild(background_); dust_container_size_ = new Rect(-Futile.screen.halfWidth*2.5f, -Futile.screen.halfHeight*2.5f, Futile.screen.width*2.5f, Futile.screen.height*2.5f); dust1_ = new Dust("Dust_4", dust_container_size_); AddChild(dust1_); tubes1_ = new FSprite("Lungs_Rear"); AddChild(tubes1_); tubes2_ = new FSprite("Lungs_MidBack1"); AddChild(tubes2_); dust2_ = new Dust("Dust_3", dust_container_size_); AddChild(dust2_); tubes3_ = new FSprite("Lungs_MiddleFore"); AddChild(tubes3_); tubes4_ = new FSprite("Lungs_Fore"); AddChild(tubes4_); dust3_ = new Dust("Dust_2", dust_container_size_); AddChild(dust3_); }
public Neuron(bool fast, Opacity opacity) : base("NeuronSlow40") { ListenForUpdate(HandleUpdate); scale = RXRandom.Range(0.1f, 0.25f); rotation = RXRandom.Range(-180.0f, 180.0f); int[] frames; string anim_name; if(fast) { frames = new int[10]; for(int i=0; i<10; i++) frames[i] = i+1; switch(opacity) { case Opacity.PERCENT_40: anim_name = "NeuronFast40"; break; case Opacity.PERCENT_60: anim_name = "NeuronFast60"; break; case Opacity.PERCENT_80: anim_name = "NeuronFast80"; break; default: anim_name = "NeuronFast40"; break; } } else { frames = new int[15]; for(int i=0; i<15; i++) frames[i] = i+1; switch(opacity) { case Opacity.PERCENT_40: anim_name = "NeuronSlow40"; break; case Opacity.PERCENT_60: anim_name = "NeuronSlow60"; break; case Opacity.PERCENT_80: anim_name = "NeuronSlow80"; break; default: anim_name = "NeuronFast40"; break; } } FAnimation animation = new FAnimation("spark", anim_name, frames, 100, false); base.addAnimation(animation); }
public EnemyCharacter(HealthBar health_bar) : base("punchy_idle") { ListenForUpdate(HandleUpdate); this.health_bar_ = health_bar; this.anchorX = .65f; this.anchorY = .6f; // set up animations // ------------------- // idle animation int[] idle_frames = { 1, 2, 3, 4 }; FAnimation idle_animation = new FAnimation("idle", "punchy_idle", idle_frames, 150, true); base.addAnimation(idle_animation); // punch animation int[] punch_frames = { 1, 2, 3, 4, 5, 6, 7 }; FAnimation punch_animation = new FAnimation("punch", "punchy_punch", punch_frames, 100, false); base.addAnimation(punch_animation); // taking damage animation int[] hit_frames = { 1, 2, 3, 4, 5, 6 }; FAnimation hit_animation = new FAnimation("hit", "punchy_hit", hit_frames, 100, false); base.addAnimation(hit_animation); // blocking animation int[] block_frames = { 1, 2, 3, 4, 5 }; FAnimation block_animation = new FAnimation("block", "punchy_block", block_frames, 100, false); base.addAnimation(block_animation); // walking animation int[] walk_frames = { 1, 2, 3, 4 }; FAnimation walk_animation = new FAnimation("walk", "punchy_walk", walk_frames, 100, true); base.addAnimation(walk_animation); int[] backwards_walk_frames = { 4, 3, 2, 1 }; FAnimation backwards_walk_animation = new FAnimation("backwards_walk", "punchy_walk", backwards_walk_frames, 100, true); base.addAnimation(backwards_walk_animation); int[] death_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; FAnimation death_animation = new FAnimation("death", "punchy_death", death_frames, 100, false); base.addAnimation(death_animation); base.setDefaultAnimation("idle"); y = -Futile.screen.halfHeight + height / 2.0f + 25.0f; x = Futile.screen.halfWidth - width / 2.0f - 150.0f; }
public void addAnimation(FAnimation anim) { _animations.Add(anim); if (_currentAnim == null) { _currentAnim = anim; _currentFrame = 0; _pause = false; } }
public PlayerSprite() : base("player_Idle") { Debug.Log("Created player sprite."); this.controller = new HumanControl(); this.idleAnim = new FAnimation("Idle", this.idleAnimFrames, 400, true); this.addAnimation(this.idleAnim); this.x = 0.0f; this.y = -10.0f; this.collRect = this.localRect.CloneAndOffset(this.x, this.y); }
//protected Vector2 centroid_ = new Vector2(.806/8.333, 1.778/6.250); public PlayerCharacter(HealthBar health_bar) : base("huro_idle") { ListenForUpdate(HandleUpdate); this.health_bar_ = health_bar; this.scaleX = .75f; this.scaleY = .75f; this.anchorX = .243f; this.anchorY = .4f; // idle animation int[] idle_frames = {1, 2, 3, 4}; FAnimation idle_animation = new FAnimation("idle", "huro_idle", idle_frames, 150, true); base.addAnimation(idle_animation); // block animation int[] block_frames = {1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 8, 9}; FAnimation block_animation = new FAnimation("block", "huro_block", block_frames, 100, false); base.addAnimation(block_animation); // punch animation int[] punch_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; FAnimation punch_animation = new FAnimation("punch", "huro_punch", punch_frames, 100, false); base.addAnimation(punch_animation); // hit animation int[] hit_frames = {1, 2, 3, 4, 5, 6}; FAnimation hit_animation = new FAnimation("hit", "huro_hit", hit_frames, 150, false); base.addAnimation(hit_animation); // walk animation int[] walk_frames = {1, 2, 3, 4}; FAnimation walk_animation = new FAnimation("walk", "huro_walk", walk_frames, 150, true); base.addAnimation(walk_animation); // backwards walk animation int[] backwards_walk_frames = {4, 3, 2, 1}; FAnimation backwards_walk_animation = new FAnimation("backwards_walk", "huro_walk", backwards_walk_frames, 150, true); base.addAnimation(backwards_walk_animation); // death animation int[] death_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; FAnimation death_animation = new FAnimation("death", "huro_death", death_frames, 150, false); base.addAnimation(death_animation); base.setDefaultAnimation("idle"); speed_ = 0.5f; y = -Futile.screen.halfHeight + height/2.0f + 25.0f; x = -Futile.screen.halfWidth + width/2.0f + 150.0f; }
public FAnimatedSprite(FAnimation defaultAnim) : base() { _animations = new List <FAnimation>(); addAnimation(defaultAnim); ListenForUpdate(Update); // default to first frame, no animation Init(FFacetType.Quad, this.GetElementWithName(defaultAnim.elementName + "_" + defaultAnim.name + "_0"), 1); // expects individual frames, in convention of NAME_#.EXT _isAlphaDirty = true; UpdateLocalVertices(); }
public void addAnimation(FAnimation anim) { _animations.Add(anim); CreateElementsForAnimation(anim); if (_currentAnim == null) { _currentAnim = anim; _currentFrame = anim.startCol; _pause = false; isVisible = true; } }
public FAnimatedSprite(FAnimation defaultAnim) : base() { _animations = new List<FAnimation>(); addAnimation(defaultAnim); ListenForUpdate(Update); // default to first frame, no animation Init(FFacetType.Quad, this.GetElementWithName(defaultAnim.elementName + "_" + defaultAnim.name + "_0"),1); // expects individual frames, in convention of NAME_#.EXT _isAlphaDirty = true; UpdateLocalVertices(); }
public EnemyCharacter(HealthBar health_bar) : base("punchy_idle") { ListenForUpdate(HandleUpdate); this.health_bar_ = health_bar; this.anchorX = .65f; this.anchorY = .6f; // set up animations // ------------------- // idle animation int[] idle_frames = {1, 2, 3, 4}; FAnimation idle_animation = new FAnimation("idle", "punchy_idle", idle_frames, 150, true); base.addAnimation(idle_animation); // punch animation int[] punch_frames = {1, 2, 3, 4, 5, 6, 7}; FAnimation punch_animation = new FAnimation("punch", "punchy_punch", punch_frames, 100, false); base.addAnimation(punch_animation); // taking damage animation int[] hit_frames = {1, 2, 3, 4, 5, 6}; FAnimation hit_animation = new FAnimation("hit", "punchy_hit", hit_frames, 100, false); base.addAnimation(hit_animation); // blocking animation int[] block_frames = {1, 2, 3, 4, 5}; FAnimation block_animation = new FAnimation("block", "punchy_block", block_frames, 100, false); base.addAnimation(block_animation); // walking animation int[] walk_frames = {1, 2, 3, 4}; FAnimation walk_animation = new FAnimation("walk", "punchy_walk", walk_frames, 100, true); base.addAnimation(walk_animation); int[] backwards_walk_frames = {4, 3, 2, 1}; FAnimation backwards_walk_animation = new FAnimation("backwards_walk", "punchy_walk", backwards_walk_frames, 100, true); base.addAnimation(backwards_walk_animation); int[] death_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; FAnimation death_animation = new FAnimation("death", "punchy_death", death_frames, 100, false); base.addAnimation(death_animation); base.setDefaultAnimation("idle"); y = -Futile.screen.halfHeight + height/2.0f + 25.0f; x = Futile.screen.halfWidth - width/2.0f - 150.0f; }
public void setFAnim(FAnimation anim) { _stopped = false; if (_currentAnim == anim) { return; } _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = Futile.atlasManager.GetElementWithName(_baseName + "/" + anim.frames[0]); }
// TODO: Add pop animation public PlayerBubble(Vector2 direction) : base("player_cell_swim") { ListenForUpdate(HandleUpdate); direction_ = direction; // turn sprite to the specified direction rotation = Mathf.Atan2(direction.x, direction.y) * 180.0f/Mathf.PI; // scale this down to a reasonable number scale = .5f; // set up the swim animation int[] swim_frames = {1, 2, 3, 4, 5, 6, 7, 8}; FAnimation swim_animation = new FAnimation("idle", "player_cell_swim", swim_frames, 250, true); base.addAnimation(swim_animation); }
public BacteriaBubble(Vector2 location, Vector2 initial_velocity) : base("punchyswarm_idle") { scale = RXRandom.Range(0.25f, 0.75f); ListenForUpdate(HandleUpdate); velocity_ = initial_velocity; SetPosition(location); int[] idle_frames = { 1, 2 }; int[] pop_frames = { 1, 2, 3, 4 }; FAnimation idle_animation = new FAnimation("idle", "punchyswarm_idle", idle_frames, 100, true); FAnimation pop_animation = new FAnimation("pop", "punchyswarm_pop", pop_frames, 100, false); base.addAnimation(idle_animation); base.addAnimation(pop_animation); }
// TODO: Add pop animation public PlayerBubble(Vector2 direction) : base("player_cell_swim") { ListenForUpdate(HandleUpdate); direction_ = direction; // turn sprite to the specified direction rotation = Mathf.Atan2(direction.x, direction.y) * 180.0f / Mathf.PI; // scale this down to a reasonable number scale = .5f; // set up the swim animation int[] swim_frames = { 1, 2, 3, 4, 5, 6, 7, 8 }; FAnimation swim_animation = new FAnimation("idle", "player_cell_swim", swim_frames, 250, true); base.addAnimation(swim_animation); }
public EnemySprite(String spriteName) : base(spriteName) { this.name = spriteName; this.SPAWN_DEPTH = PlayerState.DEPTH; if (UnityEngine.Random.Range(0.0f, 1.0f) > 0.5f) { this.RIGHT = true; } switch (spriteName) { case "fish_swim": int[] idleFishAnimFrames = { 0, 1, 0, 3 }; this.idleAnim = new FAnimation("swim_left", idleFishAnimFrames, 200, true); this.addAnimation(this.idleAnim); this.MAX_SPEED = 3.0f; this.ACCEL = 0.3f; this.behavior = new WanderHorizontal(); this.x = UnityEngine.Random.Range(-Futile.screen.halfWidth, Futile.screen.halfWidth); break; case "eel": int[] idleEelAnimFrames = { 0, 1, 0, 2 }; this.idleAnim = new FAnimation("eel_swim", idleEelAnimFrames, 100, true); this.addAnimation(this.idleAnim); this.MAX_SPEED = 5.0f; this.ACCEL = 0.5f; this.behavior = new WanderHorizontal(); this.x = UnityEngine.Random.Range(-Futile.screen.halfWidth, Futile.screen.halfWidth); break; case "jewel": int[] idleJewelAnimFrames = { 0, 1, 2 }; this.idleAnim = new FAnimation("jewel_hover", idleJewelAnimFrames, 300, true); this.addAnimation(this.idleAnim); this.behavior = new Stay(); this.x = UnityEngine.Random.Range(-Futile.screen.halfWidth + 40.0f, Futile.screen.halfWidth - 40.0f); break; default: this.behavior = new Stay(); break; } this.y = this.dy - 170.0f + (PlayerState.DEPTH - this.SPAWN_DEPTH) * 2.0f; }
public BacteriaBubble(Vector2 location, Vector2 initial_velocity) : base("punchyswarm_idle") { scale = RXRandom.Range(0.25f, 0.75f); ListenForUpdate(HandleUpdate); velocity_ = initial_velocity; SetPosition(location); int[] idle_frames = {1, 2}; int[] pop_frames = {1, 2, 3, 4}; FAnimation idle_animation = new FAnimation("idle", "punchyswarm_idle", idle_frames, 100, true); FAnimation pop_animation = new FAnimation("pop", "punchyswarm_pop", pop_frames, 100, false); base.addAnimation(idle_animation); base.addAnimation(pop_animation); }
public StomachBubble() : base("Bubble") { scale = RXRandom.Range(0.25f, 1.0f); finished_ = false; finished_count_ = 0; ListenForUpdate(HandleUpdate); int[] bubble_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; int[] ripple_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; FAnimation bubble_animation = new FAnimation("bubble", "Bubble", bubble_frames, 100, false); FAnimation ripple_animation = new FAnimation("ripple", "Ripple", ripple_frames, 100, false); base.addAnimation(bubble_animation); base.addAnimation(ripple_animation); base.play("bubble"); }
public StomachBubble() : base("Bubble") { scale = RXRandom.Range(0.25f, 1.0f); finished_ = false; finished_count_ = 0; ListenForUpdate(HandleUpdate); int[] bubble_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; int[] ripple_frames = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; FAnimation bubble_animation = new FAnimation("bubble", "Bubble", bubble_frames, 100, false); FAnimation ripple_animation = new FAnimation("ripple", "Ripple", ripple_frames, 100, false); base.addAnimation(bubble_animation); base.addAnimation(ripple_animation); base.play("bubble"); }
public void play(string animName, bool forced=false) { // check if we are given the same animation that is currently playing _pause = false; _isStopped = false; if (_currentAnim.name == animName) { if (forced) { // restart at first frame _currentFrame = 0; _time = 0; // redraw element = Futile.atlasManager.GetElementWithName(_baseName+"_"+String.Format("{0:00}",_currentAnim.frames[0])); } return; } // find the animation with the name given, no change if not found foreach (FAnimation anim in _animations) { if (anim.name == animName) { _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = Futile.atlasManager.GetElementWithName(_baseName+"_"+String.Format("{0:00}",anim.frames[0])); break; } } }
public Neuron(bool fast, Opacity opacity) : base("NeuronSlow40") { ListenForUpdate(HandleUpdate); scale = RXRandom.Range(0.1f, 0.25f); rotation = RXRandom.Range(-180.0f, 180.0f); int[] frames; string anim_name; if (fast) { frames = new int[10]; for (int i = 0; i < 10; i++) { frames[i] = i + 1; } switch (opacity) { case Opacity.PERCENT_40: anim_name = "NeuronFast40"; break; case Opacity.PERCENT_60: anim_name = "NeuronFast60"; break; case Opacity.PERCENT_80: anim_name = "NeuronFast80"; break; default: anim_name = "NeuronFast40"; break; } } else { frames = new int[15]; for (int i = 0; i < 15; i++) { frames[i] = i + 1; } switch (opacity) { case Opacity.PERCENT_40: anim_name = "NeuronSlow40"; break; case Opacity.PERCENT_60: anim_name = "NeuronSlow60"; break; case Opacity.PERCENT_80: anim_name = "NeuronSlow80"; break; default: anim_name = "NeuronFast40"; break; } } FAnimation animation = new FAnimation("spark", anim_name, frames, 100, false); base.addAnimation(animation); }
private void CreateElementsForAnimation(FAnimation anim) { float scaleInverse = Futile.resourceScaleInverse; FAtlasElement origElement = Futile.atlasManager.GetElementWithName(anim.elementName); Vector2 _textureSize = origElement.atlas.textureSize; for(int i = 0; i < anim.numFrames; i++) { FAtlasElement element = new FAtlasElement(); string name = anim.elementName + "_" + anim.name + "_" + i; element.name = name; element.isTrimmed = origElement.isTrimmed; element.atlas = origElement.atlas; element.atlasIndex = i; //the uv coordinate rectangle within the atlas float frameX = (origElement.uvRect.x * _textureSize.x) - origElement.sourceRect.x + ((anim.startCol + i) * anim.width); float frameY = (-1 * ((origElement.uvRect.y * _textureSize.y) - _textureSize.y + origElement.sourceRect.height)) - origElement.sourceRect.y + (anim.row * anim.height); float frameW = anim.width; float frameH = anim.height; Rect uvRect = new Rect ( frameX/_textureSize.x, ((_textureSize.y - frameY - frameH)/_textureSize.y), frameW/_textureSize.x, frameH/_textureSize.y ); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin,uvRect.yMax); element.uvTopRight.Set(uvRect.xMax,uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax,uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin,uvRect.yMin); //the source size is the untrimmed size element.sourcePixelSize.x = anim.width; element.sourcePixelSize.y = anim.height; element.sourceSize.x = element.sourcePixelSize.x * scaleInverse; element.sourceSize.y = element.sourcePixelSize.y * scaleInverse; //this rect is the trimmed size and position relative to the untrimmed rect float rectX = origElement.sourceRect.x; float rectY = origElement.sourceRect.y; float rectW = anim.width * scaleInverse; float rectH = anim.height * scaleInverse; element.sourceRect = new Rect(rectX,rectY,rectW,rectH); _elements.Add(element); _allElementsByName.Add(element.name, element); } }
//protected Vector2 centroid_ = new Vector2(.806/8.333, 1.778/6.250); public PlayerCharacter(HealthBar health_bar) : base("huro_idle") { ListenForUpdate(HandleUpdate); this.health_bar_ = health_bar; this.scaleX = .75f; this.scaleY = .75f; this.anchorX = .243f; this.anchorY = .4f; // idle animation int[] idle_frames = { 1, 2, 3, 4 }; FAnimation idle_animation = new FAnimation("idle", "huro_idle", idle_frames, 150, true); base.addAnimation(idle_animation); // block animation int[] block_frames = { 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 8, 9 }; FAnimation block_animation = new FAnimation("block", "huro_block", block_frames, 100, false); base.addAnimation(block_animation); // punch animation int[] punch_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; FAnimation punch_animation = new FAnimation("punch", "huro_punch", punch_frames, 100, false); base.addAnimation(punch_animation); // hit animation int[] hit_frames = { 1, 2, 3, 4, 5, 6 }; FAnimation hit_animation = new FAnimation("hit", "huro_hit", hit_frames, 150, false); base.addAnimation(hit_animation); // walk animation int[] walk_frames = { 1, 2, 3, 4 }; FAnimation walk_animation = new FAnimation("walk", "huro_walk", walk_frames, 150, true); base.addAnimation(walk_animation); // backwards walk animation int[] backwards_walk_frames = { 4, 3, 2, 1 }; FAnimation backwards_walk_animation = new FAnimation("backwards_walk", "huro_walk", backwards_walk_frames, 150, true); base.addAnimation(backwards_walk_animation); // death animation int[] death_frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; FAnimation death_animation = new FAnimation("death", "huro_death", death_frames, 150, false); base.addAnimation(death_animation); base.setDefaultAnimation("idle"); speed_ = 0.5f; y = -Futile.screen.halfHeight + height / 2.0f + 25.0f; x = -Futile.screen.halfWidth + width / 2.0f + 150.0f; }
public void play(string animName, bool forced=false) { // check if we are given the same animation that is currently playing if (_currentAnim.name == animName) { if (forced) { // restart at first frame _currentFrame = 0; _time = 0; // redraw element = this.GetElementWithName(_currentAnim.elementName + "_" + _currentAnim.name + "_" + _currentFrame); } return; } // find the animation with the name given, no change if not found foreach (FAnimation anim in _animations) { if (anim.name == animName) { _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = this.GetElementWithName(_currentAnim.elementName + "_" + _currentAnim.name + "_" + _currentFrame); break; } } }
public void play(string animName, bool forced=false) { // check if we are given the same animation that is currently playing if (_currentAnim.name == animName) { if (forced) { _finishedCount = 0; _currentFrame = 0; _time = 0; // redraw element = Futile.atlasManager.GetElementWithName(_currentAnim.filename+"_"+_currentAnim.frames[0]); } return; } // find the animation with the name given, no change if not found foreach (FAnimation anim in _animations) { if (anim.name.Equals(animName, StringComparison.Ordinal)) { //Debug.Log("Playing " + anim.name); _finishedCount = 0; _currentAnim = anim; _currentFrame = 0; _time = 0; // force redraw to first frame element = Futile.atlasManager.GetElementWithName(_currentAnim.filename+"_"+anim.frames[0]); break; } } }
private void CreateElementsForAnimation(FAnimation anim) { float scaleInverse = Futile.resourceScaleInverse; FAtlasElement origElement = Futile.atlasManager.GetElementWithName(anim.elementName); Vector2 _textureSize = origElement.atlas.textureSize; for (int i = 0; i < anim.numFrames; i++) { FAtlasElement element = new FAtlasElement(); string name = anim.elementName + "_" + anim.name + "_" + i; element.name = name; element.isTrimmed = origElement.isTrimmed; element.atlas = origElement.atlas; element.atlasIndex = i; //the uv coordinate rectangle within the atlas float frameX = (origElement.uvRect.x * _textureSize.x) - origElement.sourceRect.x + ((anim.startCol + i) * anim.width); float frameY = (-1 * ((origElement.uvRect.y * _textureSize.y) - _textureSize.y + origElement.sourceRect.height)) - origElement.sourceRect.y + (anim.row * anim.height); float frameW = anim.width; float frameH = anim.height; Rect uvRect = new Rect ( frameX / _textureSize.x, ((_textureSize.y - frameY - frameH) / _textureSize.y), frameW / _textureSize.x, frameH / _textureSize.y ); element.uvRect = uvRect; element.uvTopLeft.Set(uvRect.xMin, uvRect.yMax); element.uvTopRight.Set(uvRect.xMax, uvRect.yMax); element.uvBottomRight.Set(uvRect.xMax, uvRect.yMin); element.uvBottomLeft.Set(uvRect.xMin, uvRect.yMin); //the source size is the untrimmed size element.sourcePixelSize.x = anim.width; element.sourcePixelSize.y = anim.height; element.sourceSize.x = element.sourcePixelSize.x * scaleInverse; element.sourceSize.y = element.sourcePixelSize.y * scaleInverse; //this rect is the trimmed size and position relative to the untrimmed rect float rectX = origElement.sourceRect.x; float rectY = origElement.sourceRect.y; float rectW = anim.width * scaleInverse; float rectH = anim.height * scaleInverse; element.sourceRect = new Rect(rectX, rectY, rectW, rectH); _elements.Add(element); _allElementsByName.Add(element.name, element); } }