java - Graphic.addAnimation 调用 addAnimation

标签 java arguments processing

我运行这段代码:

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;
        }
    }
}

最佳答案

您从哪里获取以下行中的实例“图形”?

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

或者更重要的是,它的声明是什么?您无法对 Graphic 类型的变量调用 addAnimation。因为 SpriteSheet 定义了这个方法。

关于java - Graphic.addAnimation 调用 addAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166951/

相关文章:

java - 使用 java 查询 dbpedia-spotlight

actionscript-3 - 将类作为构造函数的参数传递

java - 我只想给出一个参数而不是全部 4 个

swift - 将 [Float] 转换为变量参数

java - 如何在处理2.x中启用VSync同步?

java - Mule ConsumerIterator 中缺少记录

java - 从 Spring jdbcTemplate 中的 RowMapper 获取预定义大小的列表

java - 与 equals 相比,== 运算符的使用如何带来性能改进?

Java/处理如何使用点积进行矩阵乘法

azure - 在 azure 网站上运行processing.js