ResourceAnimator.java :  » Game » easy-game-client » org » easy » gui » ani » animator » Java Open Source

Java Open Source » Game » easy game client 
easy game client » org » easy » gui » ani » animator » ResourceAnimator.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.easy.gui.ani.animator;

import org.easy.gui.Image;
import org.easy.gui.ani.sprite.ImageSprite;
import org.easy.util.NullArgumentException;
import org.easy.util.Resource;

/**
 *
 * @author Administrator
 */
public class ResourceAnimator extends IndexImageAnimator {

    protected Resource res;
    int[] indexes;
    long[] periods;

    public ResourceAnimator(ImageSprite s, Resource res, int[] indexes, long[] periods, boolean loop) {
        super(s, loop);
        NullArgumentException.check(this.res = res);
        NullArgumentException.check(this.indexes = indexes);
        NullArgumentException.check(this.periods = periods);
        if (this.indexes.length != this.periods.length) {
            throw new UnsupportedOperationException();
        }
    }

    public ResourceAnimator(ImageSprite s, Resource res, int[] indexes, long[] periods) {
        this(s, res, indexes, periods, true);
    }

    public ResourceAnimator(Resource res, int[] indexes, long[] periods, boolean loop) {
        super(loop);
        this.res = res;
        this.indexes = indexes;
        this.periods = periods;
    }

    public ResourceAnimator(Resource res, int[] indexes, long[] periods) {
        this(res, indexes, periods, true);
    }

    @Override
    public long getFramePeriodNanos(int index) {
        return periods[index];
    }

    @Override
    public Image getImage(int index) {
        return res.get(indexes[index]);
    }

    @Override
    public int count() {
        return indexes.length;
    }

    public Resource getResource() {
        return res;
    }

    public int getRealIndex() {
        return indexes[currentIndex()];
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.