Android Open Source - DemiGod Animation Utils






From Project

Back to project page DemiGod.

License

The source code is released under:

GNU General Public License

If you think the Android project DemiGod listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package high.caliber.productions.demigod.utils;
/*from w w  w. j  av  a 2s.  c  o m*/
import java.io.IOException;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;

public class AnimationUtils {

  public static final String ANIMATIONS_HOME = "drawables/x32/animations/";

  Context context;

  public AnimationUtils(Context context) {
    this.context = context;
  }

  public class Fireball extends ImageView {

    Context context;

    AssetManager manager;
    Drawable fireball;
    AnimationDrawable anim = new AnimationDrawable();

    public Fireball(Context context) {
      super(context);
      this.context = context;

      manager = context.getAssets();

      return;
    }

    public void startFireball(final int destX) {

      Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {

          setVisibility(View.VISIBLE);
          try {
            fireball = Drawable.createFromStream(
                manager.open(ANIMATIONS_HOME + "fireball1.png"),
                null);
            anim.addFrame(fireball, 200);

            fireball = Drawable.createFromStream(
                manager.open(ANIMATIONS_HOME + "fireball2.png"),
                null);
            anim.addFrame(fireball, 200);

            anim.setOneShot(false);
            setImageDrawable(anim);
            anim.start();

          } catch (IOException e) {
            e.printStackTrace();
          }

          for (int i = (int) getX(); i > destX; i--) {
            setX(i);
          }
          hit();

        }
      });

      post(thread);

    }

    private void hit() {

      AnimationDrawable anim = new AnimationDrawable();
      try {

        fireball = Drawable.createFromStream(
            manager.open(ANIMATIONS_HOME + "fireball3.png"), null);
        anim.addFrame(fireball, 200);

        fireball = Drawable.createFromStream(
            manager.open(ANIMATIONS_HOME + "fireball4.png"), null);
        anim.addFrame(fireball, 200);

        fireball = Drawable.createFromStream(
            manager.open(ANIMATIONS_HOME + "fireball5.png"), null);
        anim.addFrame(fireball, 200);

        anim.setOneShot(true);

        setImageDrawable(anim);
        anim.start();
      } catch (IOException e) {
        e.printStackTrace();
      }

    }

  }
}




Java Source Code List

high.caliber.productions.demigod.Enemy.java
high.caliber.productions.demigod.Hero.java
high.caliber.productions.demigod.Item.java
high.caliber.productions.demigod.Map.java
high.caliber.productions.demigod.Tile.java
high.caliber.productions.demigod.XmlActivityTest.java
high.caliber.productions.demigod.activity.BattleLog.java
high.caliber.productions.demigod.activity.Battle_Activity.java
high.caliber.productions.demigod.activity.CreateHero.java
high.caliber.productions.demigod.activity.HomeTown.java
high.caliber.productions.demigod.activity.Home.java
high.caliber.productions.demigod.activity.Inventory.java
high.caliber.productions.demigod.activity.Status.java
high.caliber.productions.demigod.activity.TitleScreen.java
high.caliber.productions.demigod.database.EnemyDB.java
high.caliber.productions.demigod.database.HeroDB.java
high.caliber.productions.demigod.database.ItemDB.java
high.caliber.productions.demigod.settings.DpadPosition.java
high.caliber.productions.demigod.settings.DpadSizePref.java
high.caliber.productions.demigod.settings.SettingsMain.java
high.caliber.productions.demigod.utils.AnimationUtils.java
high.caliber.productions.demigod.utils.InventoryAdapter.java
high.caliber.productions.demigod.utils.LevelUpWorker.java
high.caliber.productions.demigod.utils.PixelUnitConverter.java
high.caliber.productions.demigod.utils.SharedPrefsManager.java
high.caliber.productions.demigod.utils.XmlMapAdapter.java