我正在开发一个简单的马里奥侧卷轴,当我尝试调用 Scrolling 对象的scroll()方法时,我得到了无法找到符号 - 方法 scroll()引发的错误。请帮忙!
这是子世界文件
import greenfoot.*;
import java.util.ArrayList;
/**
* Write a description of class MarioWorld here.
*
* @author (your name)
* @version (a version number or a
public class MarioWorld extends World
{
ArrayList<MovingActor> moving = new ArrayList<MovingActor>();
ArrayList<Actor> things = new ArrayList<Actor>();
Message messagebox = new Message("");
/**
* Constructor for objects of class MarioWorld.
*
*/
public MarioWorld()
{
super(800, 600, 1);
for(int i = 0; i < 40; i++)
{
things.add(new GreenApple());
things.add(new Shamrock());
}
for(int i = 0; i<8;i++)
things.add(new Brick());
moving.add(new Mario());
for(int r = 0;r < things.size();r++)
{
addObject(things.get(r),Greenfoot.getRandomNumber(800),Greenfoot.getRandomNumber(600));
}
}
public void act()
{
for(int i = 0;i < things.size();i++)
{
things.get(i).scroll();
}
addObject(moving.get(0),15,300);
moving.get(0).worldact();
}
}
`
这是 3 个滚动类之一(除了名称/图片外,它们是相同的
import greenfoot.*;
public class Shamrock extends Actor implements Scrollable
{
/**
* Act - do whatever the Shamrock wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public Actor worldact()
{
scroll();
return this;
}
public void scroll()
{
int x = getX();
int y = getY();
if(x <= 0)
x = 800;
x -= 6;
setLocation(x,y);
}
}
这是“可滚动”界面
import greenfoot.*;
public interface Scrollable
{
public void scroll();
}