Android Open Source - RockFall-Android Sprite






From Project

Back to project page RockFall-Android.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project RockFall-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 eu.raffprta.rockfall.core.sprite;
// w w w .  j  av  a2 s .c o m
import android.graphics.Bitmap;

import eu.raffprta.rockfall.app.SpriteContainer;

/**
 * A class resembling a Sprite object, which can be affixed to objects
 * that are SpriteContainers (like Entities and Tiles)
 * This class allows Sprite factories to use SpriteSheet objects to load
 * whole or partial images.
 * @author Raffaello Perrotta
 *
 */

public class Sprite implements SpriteContainer{

    private SpriteSheet s;
    private int col;
    private int row;
    private int cellWidth;
    private int cellHeight;
    private final String NAME;
    private boolean isWhole;
    private Bitmap cachedBit;

    public Sprite(SpriteSheet s, int col, int row, int cellWidth, int cellHeight, final String NAME){
        this.s = s;
        this.col = col;
        this.row = row;
        this.cellWidth = cellWidth;
        this.cellHeight = cellHeight;
        this.NAME = NAME;
        this.isWhole = false;
    }

    public Sprite(SpriteSheet s, final String NAME){
        this.s = s;
        this.NAME = NAME;
        this.isWhole = true;
    }

    public Bitmap getSprite(){
        if(this.isWhole)
            return getWholeImage();
        return getPartialImage();
    }

    public Bitmap getPartialImage(){
        if(cachedBit == null)
            cachedBit = s.getCell(this.col, this.row, this.cellWidth, this.cellHeight);
        return cachedBit;
    }

    public Bitmap getWholeImage(){
        if(cachedBit == null)
            cachedBit = s.getWhole();
        return cachedBit;
    }

    public String toString(){
        return this.NAME;
    }

}




Java Source Code List

eu.raffprta.rockfall.app.GameCanvas.java
eu.raffprta.rockfall.app.GameIntent.java
eu.raffprta.rockfall.app.GameScreen.java
eu.raffprta.rockfall.app.MainGame.java
eu.raffprta.rockfall.app.MenuCanvas.java
eu.raffprta.rockfall.app.SpriteContainer.java
eu.raffprta.rockfall.app.StopWatch.java
eu.raffprta.rockfall.app.TouchHandler.java
eu.raffprta.rockfall.core.entity.AbstractEntity.java
eu.raffprta.rockfall.core.entity.EntityFactory.java
eu.raffprta.rockfall.core.entity.Entity.java
eu.raffprta.rockfall.core.entity.FallableType.java
eu.raffprta.rockfall.core.entity.Fallable.java
eu.raffprta.rockfall.core.entity.Powerup.java
eu.raffprta.rockfall.core.entity.Protagonist.java
eu.raffprta.rockfall.core.entity.Rock.java
eu.raffprta.rockfall.core.sprite.SpriteFactory.java
eu.raffprta.rockfall.core.sprite.SpriteSheet.java
eu.raffprta.rockfall.core.sprite.Sprite.java