Android Open Source - snappyfrog Power Bar






From Project

Back to project page snappyfrog.

License

The source code is released under:

Apache License

If you think the Android project snappyfrog 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.masseranolabs.snappyfrog;
//from   w w  w.  j  a  v a 2 s.  co m
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;

public class PowerBar extends Actor {
  private Array<Sprite> frames;
  private int currentFrame;
  private long lastUpdateFrameTime;
  private boolean activated;
  private int holdCount;
  
  public PowerBar(){
    super();
    
    activated = false;
    frames = Game.getTextureAtlas().createSprites("gamescene/powerbar");
    
    currentFrame = 0;
    holdCount = 0;
    lastUpdateFrameTime = 0;
  }
  
  public void activate(){
    activated = true;
  }
  
  public int deactivate(){
    activated = false;
    return currentFrame;
  }
  
  private void updateFrame(){
    // Limit frame update to every 1/20th of second
    if (TimeUtils.nanoTime() - lastUpdateFrameTime > 25000000){
      if (activated){
        if (++currentFrame == frames.size){
          if (holdCount++ != 4){
            currentFrame = frames.size - 1;
          }else{
            currentFrame = 0;
            holdCount = 0;
          }
        }        
      }else{
        currentFrame = 0;
        holdCount = 0;
      }
      
      lastUpdateFrameTime = TimeUtils.nanoTime();
    }
  }
  
  @Override
  public float getWidth() {
    return frames.get(0).getWidth();
  }
  
  @Override
  public float getHeight() {
    return frames.get(0).getHeight();
  }  
  
  @Override
  public void act(float delta) {
    super.act(delta);
    
    updateFrame();
  }
  
  @Override
  public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
    
    Color color = getColor();
        batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    batch.draw(frames.get(currentFrame), getX(), getY(), getOriginX(), getOriginY(),
                getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
  }
}




Java Source Code List

com.masseranolabs.bridge.SLComposeViewController.java
com.masseranolabs.snappyfrog.AndroidServices.java
com.masseranolabs.snappyfrog.ButtonFactory.java
com.masseranolabs.snappyfrog.DesktopServices.java
com.masseranolabs.snappyfrog.Explosion.java
com.masseranolabs.snappyfrog.Frog.java
com.masseranolabs.snappyfrog.Game.java
com.masseranolabs.snappyfrog.LaserBeam.java
com.masseranolabs.snappyfrog.LevelScreen.java
com.masseranolabs.snappyfrog.MainActivity.java
com.masseranolabs.snappyfrog.MainActivity.java
com.masseranolabs.snappyfrog.Main.java
com.masseranolabs.snappyfrog.Obstacle.java
com.masseranolabs.snappyfrog.OuyaServices.java
com.masseranolabs.snappyfrog.PlatformServices.java
com.masseranolabs.snappyfrog.PowerBar.java
com.masseranolabs.snappyfrog.ResHelper.java
com.masseranolabs.snappyfrog.RobovmLauncher.java
com.masseranolabs.snappyfrog.Salary.java
com.masseranolabs.snappyfrog.ScreenshotFactory.java
com.masseranolabs.snappyfrog.StagedScreen.java
com.masseranolabs.snappyfrog.client.GwtLauncher.java
com.masseranolabs.snappyfrog.client.HtmlServices.java
com.masseranolabs.snappyfrog.iOSServices.java
org.robovm.bindings.admob.GADAdMobExtras.java
org.robovm.bindings.admob.GADAdNetworkExtras.java
org.robovm.bindings.admob.GADAdSizeManager.java
org.robovm.bindings.admob.GADAdSize.java
org.robovm.bindings.admob.GADBannerViewDelegateAdapter.java
org.robovm.bindings.admob.GADBannerViewDelegate.java
org.robovm.bindings.admob.GADBannerView.java
org.robovm.bindings.admob.GADErrorCode.java
org.robovm.bindings.admob.GADGender.java
org.robovm.bindings.admob.GADInterstitialDelegateAdapter.java
org.robovm.bindings.admob.GADInterstitialDelegate.java
org.robovm.bindings.admob.GADInterstitial.java
org.robovm.bindings.admob.GADRequestErrorConstants.java
org.robovm.bindings.admob.GADRequestError.java
org.robovm.bindings.admob.GADRequest.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialAdapter.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialDelegateAdapter.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitialDelegate.java
org.robovm.bindings.admob.mediation.GADCustomEventInterstitial.java
org.robovm.bindings.admob.mediation.GADCustomEventRequest.java
org.robovm.bindings.admob.sample.Sample.java