我运行此代码:

graphic.addAnimation("standart",new int[] {0,1},1.0,true);


将调用graphic.addAnimation(String,int [],float,boolean)方法:

public void addAnimation(String nme,int[] frmes,float time,boolean loop) {
        animations.push(new Aim(nme, frmes, time, loop));
    }


但是我得到这个错误:

the function addAnimation(String,int[],float,boolean) does not exist.


SpriteSheet:

package progame;

import java.util.Stack;

import processing.core.PImage;

public class SpriteSheet extends Graphic {
    public int height,width,index;
    public int timer;
    public String playing;
    public Stack<PImage> sheet = new Stack<PImage>();
    public Stack<Aim> animations = new Stack<Aim>();

    public SpriteSheet(String path,int h,int w) {
        super(path);
        height = h;
        width = w;
        for(int i = 0; i < Math.floor(source.height/height); i++) {
            for(int j = 0; j < Math.floor(source.width/width); j++) {
                sheet.push(source.get(j*width, i*height, width, height));
            }
        }
    }

    public SpriteSheet(String path,Entity e,int h,int w) {
        super(path,e);
        height = h;
        width = w;
        for(int i = 0; i < Math.floor(source.height/height); i++) {
            for(int j = 0; j < Math.floor(source.width/width); j++) {
                sheet.push(source.get(j*width, i*height, width, height));
            }
        }
    }

    public Aim getAnimation(String name) {
        for(int i = 0; i< animations.size(); i++)
        {
            if(animations.get(i).name == name) {
                return(animations.get(i));
            }
        }
        return null;
    }

    public void play(String name) {
        for(int i = 0; i< animations.size(); i++)
        {
            if(animations.get(i).name == name) {
                playing = name;
                index = 0;
                timer = 0;
            }else
            {
                playing = null;
                return;
            }
        }
    }

    public void update() {
        timer ++;
        Aim aim = getAnimation(playing);
        if( timer > aim.frameRate)
        {
            timer = 0;
            if(index == aim.frames.length)
            {
                if(aim.looping) {
                    index = 0;
                }else
                {
                    playing = null;
                }
            }else
            {
                index++;
            }
        }
        source = sheet.get(index);
    }

    public void render() {
        update();
        super.render();
    }

    public void addAnimation(String nme,int[] frmes,float time,boolean loop) {
        animations.push(new Aim(nme, frmes, time, loop));
    }

    private class Aim
    {
        String name;
        int[] frames;
        float frameRate;
        boolean looping;
        public Aim(String nme,int[] frmes,float time,boolean loop)
        {
            name = nme;
            frames = frmes;
            frameRate = time;
            looping = loop;
        }
    }
}

最佳答案

你说


  它在Entity类中声明,如下所示:public Graphic graphic;


声明为:

public SpriteSheet graphic;

10-06 14:35