Android Open Source - ssniper-andengine Sprite Manager






From Project

Back to project page ssniper-andengine.

License

The source code is released under:

Apache License

If you think the Android project ssniper-andengine 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.cladophora.ssniper;
/*from w ww.j a v  a2 s .  c  o m*/
import android.content.res.AssetManager;
import android.graphics.Color;
import org.andengine.entity.scene.background.RepeatingSpriteBackground;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.font.FontManager;
import org.andengine.opengl.texture.ITexture;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

/**
 * Created by jmar on 1/29/14.
 */
public class SpriteManager {
    public static ITextureRegion mf1TR;
    public static ITextureRegion mf2TR;
    public static ITextureRegion mf3TR;
    public static ITextureRegion mf4TR;
    public static ITextureRegion mf5TR;
    public static ITextureRegion mf6TR;
    public static ITextureRegion ms3TR;
    public static ITextureRegion ms4TR;
    public static ITextureRegion mC1TR;
    public static ITextureRegion mC4TR;
    public static ITextureRegion mAmmoTR;
    public static ITextureRegion mBCaseTR;
    public static ITextureRegion mCrateTR;
    public static ITextureRegion mMedkitTR;
    public static ITextureRegion mHealthTR;
    public static ITextureRegion mCashTR;
    public static ITextureRegion mRifleTR;
    public static ITextureRegion mReloadIconTR;
    public static ITextureRegion mCasingIconTR;
    public static ITextureRegion mBulletIconTR;
    public static ITextureRegion mFlashTR;
    public static ITextureRegion mGlassTR;
    public static ITextureRegion mTargetTR;
    public static ITextureRegion mflash1TR;
    public static ITextureRegion mflash2TR;
    public static ITextureRegion mflash3TR;
    public static ITextureRegion mflash4TR;
    public static ITextureRegion mflash5TR;
    public static ITextureRegion mClockTR;
    public static ITextureRegion mDoorTR;
    public static ITextureRegion mTree1TR;
    public static ITextureRegion mTree2TR;
    public static ITextureRegion mTree3TR;
    public static ITextureRegion mPlant1TR;
    public static ITextureRegion mCactus1TR;
    public static ITextureRegion mCactus2TR;
    public static ITextureRegion mCactus3TR;
    public static ITextureRegion mCactus4TR;
    public static RepeatingSpriteBackground mSnowBGTR;
    public static RepeatingSpriteBackground mSandBGTR;
    public static RepeatingSpriteBackground mGrassBGTR;
    public static BitmapTextureAtlas mEnemyBTA;
    public static BitmapTextureAtlas mEffectsBTA;
    public static BitmapTextureAtlas mWildlifeBTA;
    public static Sprite sprite;
    public static Sprite casing;
    public static Sprite flash;
    public static Sprite bullet0;
    public static Sprite bullet1;
    public static Sprite bullet2;
    public static Sprite bullet3;
    public static Sprite bullet4;

    public static void loadPlantTextureRegions() {
        BaseActivity context = BaseActivity.getSharedInstance();
        TextureManager textureManager = context.getTextureManager();
        mWildlifeBTA = new BitmapTextureAtlas(textureManager, 1024, 1024, TextureOptions.BILINEAR);

        // row 1 height= 512
        mTree1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "tree1.png", 0, 0);
        mTree2TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "tree2.png", 245, 0);
        mTree3TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "tree3.png", 566, 0);

        // row 2 height = 512
        mCactus1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "cactus1.png", 0, 512);
        mCactus2TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "cactus2.png", 76, 512);
        mCactus3TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "cactus3.png", 284, 512);
        mCactus4TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "cactus3.png", 419, 512);
        mPlant1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mWildlifeBTA, context, "plant1.png", 579, 512);

        mWildlifeBTA.load();
    }

    public static void loadGameEffectTextureRegions() {
        BaseActivity context = BaseActivity.getSharedInstance();
        TextureManager textureManager = context.getTextureManager();
        mEffectsBTA = new BitmapTextureAtlas(textureManager, 512, 512, TextureOptions.BILINEAR);
        mGlassTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEffectsBTA, context, "glass.png", 0, 0);
        mEffectsBTA.load();
    }

    public static void loadEnemyTextureRegions() {
        BaseActivity context = BaseActivity.getSharedInstance();
        TextureManager textureManager = context.getTextureManager();
        mEnemyBTA = new BitmapTextureAtlas(textureManager, 1024, 1024, TextureOptions.BILINEAR);

        // row 1 height=256
        mf1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f1.png", 0, 0);
        mf2TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f2.png", 99, 0);
        mf3TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f3.png", 210, 0);
        mf4TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f4.png", 305, 0);
        mf5TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f5.png", 394, 0);
        mf6TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "f6.png", 469, 0);
        ms3TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "s3.png", 594, 0);
        ms4TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "s4.png", 759, 0);

        //Log.v("BaseActivity.loadGraphics()","Creating row 2 of BitmapTextureAtlas");
        // row 2 height=196
        mC1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "c1.png", 0, 257);
        mC4TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "c4.png", 163, 257);
        mAmmoTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "ammo.png", 305, 257);
        mBCaseTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "briefcase.png", 435, 257);
        mCrateTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "crate.png", 497, 257);
        mMedkitTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "medkit.png", 625, 257);
        mHealthTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "health.png", 753, 257);
        mCashTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "cash.png", 882, 257);

        //Log.v("BaseActivity.loadGraphics()","Creating row 3 of BitmapTextureAtlas");
        // row 3 height = 360
        mRifleTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "rifle.png", 0, 453);
        mReloadIconTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "reload.png", 601, 453);
        mCasingIconTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "casing.png", 649, 453);
        mBulletIconTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "bullet.png", 777, 453);
        mTargetTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "target.png", 905, 453);

        // row 4 height = 211 begins at 813
        mFlashTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash.png", 0, 813);
        mflash1TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash1.png", 221, 813);
        mflash2TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash2.png", 317, 813);
        mflash3TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash3.png", 413, 813);
        mflash4TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash4.png", 509, 813);
        mflash5TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "flash5.png", 605, 813);
        mClockTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "clock.png", 701, 813);
        mDoorTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mEnemyBTA, context, "door.png", 829, 813);

        mEnemyBTA.load();
    }

    public static void loadGameBackgrounds () {
        TextureManager textureManager = BaseActivity.getSharedInstance().getTextureManager();
        AssetManager assets = BaseActivity.getSharedInstance().getAssets();
        VertexBufferObjectManager vertexBufferObjectManager = BaseActivity.getSharedInstance().getVertexBufferObjectManager();
        // load game background
        mSnowBGTR = new RepeatingSpriteBackground(BaseActivity.CAMERA_WIDTH, BaseActivity.CAMERA_HEIGHT, textureManager, AssetBitmapTextureAtlasSource.create(assets, "gfx/snowbg.png"), vertexBufferObjectManager);
        mGrassBGTR = new RepeatingSpriteBackground(BaseActivity.CAMERA_WIDTH, BaseActivity.CAMERA_HEIGHT, textureManager, AssetBitmapTextureAtlasSource.create(assets, "gfx/grassbg.png"), vertexBufferObjectManager);
        mSandBGTR = new RepeatingSpriteBackground(BaseActivity.CAMERA_WIDTH, BaseActivity.CAMERA_HEIGHT, textureManager, AssetBitmapTextureAtlasSource.create(assets, "gfx/sandbg.png"), vertexBufferObjectManager);
    }

    static void loadGraphics() {
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        loadGameBackgrounds();
        loadEnemyTextureRegions();
        loadPlantTextureRegions();
        loadGameEffectTextureRegions();
    }

    public static void initializeRifleSprites() {
        final VertexBufferObjectManager vbom = BaseActivity.getSharedInstance().getVertexBufferObjectManager();
        sprite = new Sprite(0, BaseActivity.CAMERA_HEIGHT - mRifleTR.getHeight(), mRifleTR, vbom);
        casing = new Sprite(0,0, mCasingIconTR,vbom);
        flash = new Sprite(0,0, mFlashTR,vbom);
        bullet0 = new Sprite(0,0, mBulletIconTR,vbom);
        bullet1 = new Sprite(0,0, mBulletIconTR,vbom);
        bullet2 = new Sprite(0,0, mBulletIconTR,vbom);
        bullet3 = new Sprite(0,0, mBulletIconTR,vbom);
        bullet4 = new Sprite(0,0, mBulletIconTR,vbom);
        flash.setScaleCenter(0, 0);
        flash.setRotationCenter(0, 0);
        flash.setRotation(-30);
        flash.setVisible(false);
        casing.setScaleCenter(0, 0);
        casing.setScale(0.5f);
        casing.setRotationCenter(casing.getWidthScaled() / 2, casing.getHeightScaled() / 2);
        casing.setVisible(false);
    }

    public static void loadFonts() {
        final TextureManager textureManager = BaseActivity.getSharedInstance().getTextureManager();
        final FontManager fontManager = BaseActivity.getSharedInstance().getFontManager();
        final AssetManager assets = BaseActivity.getSharedInstance().getAssets();
        FontFactory.setAssetBasePath("font/");

        // Load ttf font
        final ITexture notoSansFontTexture = new BitmapTextureAtlas(textureManager, 512, 512, TextureOptions.BILINEAR);
        final ITexture digitFontTexture    = new BitmapTextureAtlas(textureManager, 256, 256, TextureOptions.BILINEAR);
        final ITexture digitFontLTexture   = new BitmapTextureAtlas(textureManager, 256, 256, TextureOptions.BILINEAR);
        int fontSize = 48;

        BaseActivity.mNotoSansFont = FontFactory.createFromAsset(fontManager, notoSansFontTexture, assets, "NotoSans-Regular.ttf", fontSize, true, Color.WHITE);
        BaseActivity.mDigitFont    = FontFactory.createFromAsset(fontManager, digitFontTexture, assets, "LED.ttf", fontSize, true, Color.WHITE);

        // set color to white so we can change colors later
        BaseActivity.mDigitFontL   = FontFactory.createFromAsset(fontManager, digitFontLTexture, assets, "LED.ttf", fontSize * 2, true, Color.WHITE);

        BaseActivity.mNotoSansFont.load();
        BaseActivity.mDigitFont.load();
        BaseActivity.mDigitFontL.load();
    }
}




Java Source Code List

com.cladophora.ssniper.BaseActivity.java
com.cladophora.ssniper.DeviceUtil.java
com.cladophora.ssniper.EnemyPool.java
com.cladophora.ssniper.GameEffects.java
com.cladophora.ssniper.GameEvents.java
com.cladophora.ssniper.GameLoopUpdateHandler.java
com.cladophora.ssniper.GameUtil.java
com.cladophora.ssniper.HUDManager.java
com.cladophora.ssniper.HoverListener.java
com.cladophora.ssniper.ItemPool.java
com.cladophora.ssniper.LevelLoader.java
com.cladophora.ssniper.PlantPool.java
com.cladophora.ssniper.SPenHoverView.java
com.cladophora.ssniper.ScopeEngine.java
com.cladophora.ssniper.SoundManager.java
com.cladophora.ssniper.SpriteManager.java
com.cladophora.ssniper.andengine.IRandomTimerCallBack.java
com.cladophora.ssniper.andengine.RandomTimerHandler.java
com.cladophora.ssniper.entity.EnemyLayer.java
com.cladophora.ssniper.entity.Enemy.java
com.cladophora.ssniper.entity.ItemLayer.java
com.cladophora.ssniper.entity.Item.java
com.cladophora.ssniper.entity.PlantLayer.java
com.cladophora.ssniper.entity.Plant.java
com.cladophora.ssniper.entity.Reticle.java
com.cladophora.ssniper.entity.Rifle.java
com.cladophora.ssniper.entity.SPen.java
com.cladophora.ssniper.scene.GameScene.java
com.cladophora.ssniper.scene.InstructionScene.java
com.cladophora.ssniper.scene.IntroScene.java
com.cladophora.ssniper.scene.MainMenuScene.java
com.cladophora.ssniper.scene.PauseScene.java
com.cladophora.ssniper.scene.ResultScene.java
com.cladophora.ssniper.scene.ShopScene.java
com.cladophora.ssniper.scene.SplashScene.java
com.cladophora.ssniper.scene.SurvivorIntroScene.java
com.cladophora.ssniper.scene.SurvivorScene.java
com.cladophora.ssniper.scene.TutorialScene.java
com.cladophora.ssniper.scene.WeaponInfoScene.java