首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >graphic.addAnimation调用addAnimation

graphic.addAnimation调用addAnimation
EN

Stack Overflow用户
提问于 2011-05-29 09:32:00
回答 3查看 112关注 0票数 0

我运行以下代码:

代码语言:javascript
复制
graphic.addAnimation("standart",new int[] {0,1},1.0,true);

它调用graphic.addAnimation(字符串、int[]、浮点数、布尔值)方法:

代码语言:javascript
复制
public void addAnimation(String nme,int[] frmes,float time,boolean loop) {
    animations.push(new Aim(nme, frmes, time, loop));
}

但我知道这个错误:

函数addAnimation(字符串、int[]、浮点、布尔)不存在。

SpriteSheet:

代码语言:javascript
复制
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;
        }
    }
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-29 10:18:56

你说过

在其声明的实体类中,如下所示:公共图形;

声明为:

代码语言:javascript
复制
public SpriteSheet graphic;
票数 0
EN

Stack Overflow用户

发布于 2011-05-29 10:09:02

下面一行中的实例“图形”是从哪里获得的?

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

或者更重要的是,它的声明是什么?不能对类型为addAnimation的变量调用Graphic。因为定义此方法的是SpriteSheet

票数 1
EN

Stack Overflow用户

发布于 2011-05-29 10:55:19

基于OP的评论:its declared in the Entity class, like this: public Graphic graphic;

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

就能解决问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6166951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档