Android Open Source - Slime-Volleyball-for-Android Animated Sprite






From Project

Back to project page Slime-Volleyball-for-Android.

License

The source code is released under:

Copyright (c) 2011 Philip Bjorge Permission is hereby granted, free of charge, to any person obtaining a copy of this hardware, software, and associated documentation files (the "Product"), to deal i...

If you think the Android project Slime-Volleyball-for-Android 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 com.philipbjorge;
/*from  w w  w.  j  av a  2 s . c  o m*/
import java.util.ArrayList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;

public class AnimatedSprite {
  int currentFrame;
  int frequency;
  int count;
  int maxFrame;
  
  ArrayList<Bitmap> frames;
  
  Bitmap current;
  boolean isStatic;
  
  public AnimatedSprite(int rID, int frameWidth, int frameHeight, float w, float h, int frameCount, int frequency, Resources r, boolean isS) {
    count = 0;
    currentFrame = 0;
    this.frequency = frequency;
    isStatic = isS;
    
    //int frameWidth = (int) drawFrame.width();
    frames = new ArrayList<Bitmap>();
    for(int i = 0; i < frameCount; i++) {
      Bitmap b = Bitmap.createBitmap(BitmapFactory.decodeResource(r, rID), (i*frameWidth), 0, frameWidth, frameHeight);
      frames.add(Bitmap.createScaledBitmap(b, (int)w, (int)h, true));
    }
    maxFrame = frames.size();
    current = frames.get(0);
  }
  
  public void update() {
    if(!isStatic) {
      if(count > 59)
        count = 0;
      if(currentFrame == maxFrame)
        currentFrame = 0;
      
      if(count%frequency == 0) {
        current = frames.get(currentFrame);
        currentFrame++;
      }
      
      count++;
    }
  }
  
  public Bitmap getBitmap() {
    return current;
  }
}




Java Source Code List

com.philipbjorge.AI.java
com.philipbjorge.AnimatedSprite.java
com.philipbjorge.GameThread.java
com.philipbjorge.GameView.java
com.philipbjorge.Game.java
com.philipbjorge.Match.java
com.philipbjorge.PhysicsEngine.java
com.philipbjorge.RigidBody.java
com.philipbjorge.Settings.java
com.philipbjorge.SlimeVolleyball.java