Android Open Source - libgdx-demo-pax-britannica Background F X Renderer






From Project

Back to project page libgdx-demo-pax-britannica.

License

The source code is released under:

Copyright (c) 2010 Ben Abraham, Renaud B?dard, Henk Boom, Daniel Burton, Matthew Gallant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated ...

If you think the Android project libgdx-demo-pax-britannica 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 de.swagner.paxbritannica.background;
/*from  w  w w .  ja v  a2  s .  c o m*/
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Array;

import de.swagner.paxbritannica.Resources;

public class BackgroundFXRenderer {

  SpriteBatch backgroundFXBatch;
  Array<Debris> debrises = new Array<Debris>();
  
  Array<Fish> fishes = new Array<Fish>();
  
  SpriteBatch backgroundBatch;
  Sprite background;  

  public BackgroundFXRenderer() {
    createDebris();
    createFishes();
    backgroundFXBatch = new SpriteBatch();
    backgroundFXBatch.getProjectionMatrix().setToOrtho2D(0, 0, 800, 480);
    
    background = Resources.getInstance().background;
    backgroundBatch = new SpriteBatch();
    backgroundBatch.getProjectionMatrix().setToOrtho2D(0, 0, 128, 128);
  }

  private void createDebris() {
    for(int i = 0; i<30;++i) {
      debrises.add(new Debris(new Vector2(MathUtils.random(-100, 800),MathUtils.random(-200, 400))));
    }
  }
  
  private void createFishes() {
    for(int i = 0; i<15;++i) {
      fishes.add(new Fish(new Vector2(MathUtils.random(-100, 800),MathUtils.random(-200, 400))));
    }
  }

  float stateTime = 0;
  Vector3 lerpTarget = new Vector3();

  public void render() {    
    backgroundBatch.begin();
    background.draw(backgroundBatch);
    backgroundBatch.end();
    
    backgroundFXBatch.begin();
    for (Debris debris : debrises) {
      if (debris.alive) {
        debris.draw(backgroundFXBatch);
      } else {
        debris.reset();
      }
    }
    for (Fish fish : fishes) {
      if (fish.alive) {
        fish.draw(backgroundFXBatch);
      } else {
        fish.reset();
      }
    }
    backgroundFXBatch.end();    
  }
  
  public void resize(int width, int height) {
    backgroundFXBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
  }
  
  public void dispose() {
    fishes.clear();
    debrises.clear();
    backgroundFXBatch.dispose();
    backgroundBatch.dispose();
  }
  
}




Java Source Code List

de.swagner.paxbritannica.Bullet.java
de.swagner.paxbritannica.Collision.java
de.swagner.paxbritannica.Constants.java
de.swagner.paxbritannica.DefaultScreen.java
de.swagner.paxbritannica.GameInstance.java
de.swagner.paxbritannica.GameScreen.java
de.swagner.paxbritannica.IOSLauncher.java
de.swagner.paxbritannica.PaxBritannica.java
de.swagner.paxbritannica.Resources.java
de.swagner.paxbritannica.Ship.java
de.swagner.paxbritannica.Targeting.java
de.swagner.paxbritannica.android.AndroidLauncher.java
de.swagner.paxbritannica.background.BackgroundFXRenderer.java
de.swagner.paxbritannica.background.Debris.java
de.swagner.paxbritannica.background.Fish.java
de.swagner.paxbritannica.bomber.Bomb.java
de.swagner.paxbritannica.bomber.BomberAI.java
de.swagner.paxbritannica.bomber.Bomber.java
de.swagner.paxbritannica.client.HtmlLauncher.java
de.swagner.paxbritannica.desktop.DesktopLauncher.java
de.swagner.paxbritannica.factory.EasyEnemyProduction.java
de.swagner.paxbritannica.factory.FactoryProduction.java
de.swagner.paxbritannica.factory.HardEnemyProduction.java
de.swagner.paxbritannica.factory.MediumEnemyProduction.java
de.swagner.paxbritannica.factory.PlayerProduction.java
de.swagner.paxbritannica.factory.Production.java
de.swagner.paxbritannica.fighter.FighterAI.java
de.swagner.paxbritannica.fighter.Fighter.java
de.swagner.paxbritannica.fighter.Laser.java
de.swagner.paxbritannica.frigate.FrigateAI.java
de.swagner.paxbritannica.frigate.Frigate.java
de.swagner.paxbritannica.frigate.MissileAI.java
de.swagner.paxbritannica.frigate.Missile.java
de.swagner.paxbritannica.help.Help.java
de.swagner.paxbritannica.mainmenu.Countdown.java
de.swagner.paxbritannica.mainmenu.FactorySelector.java
de.swagner.paxbritannica.mainmenu.MainMenu.java
de.swagner.paxbritannica.particlesystem.BigBubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.BubbleParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ExplosionParticleEmitter.java
de.swagner.paxbritannica.particlesystem.ParticleEmitter.java
de.swagner.paxbritannica.particlesystem.Particle.java
de.swagner.paxbritannica.particlesystem.SparkParticleEmitter.java
de.swagner.paxbritannica.settings.Settings.java