This site requires JavaScript, please enable it in your browser!
Greenfoot back
Fire
Fire wrote ...

2022/11/28

How Do I make Camera movement only go Horizontal and vertical at a certain height?

1
2
3
danpost danpost

2022/12/7

#
Fire wrote...
How would I fix the error message with Scroller, Range, and scroll classes?
Copy/paste the error message here along with any relevant codes.
Fire Fire

2022/12/7

#
danpost wrote...
Copy/paste the error message here along with any relevant codes.
Error messages for the ImageScrollWorld Constructor Range in class Range in class Range cannot be applied to given types; required: no arguments found: boolean reason: actual and formal argument lists differ in length this error pops up twice I have put the same code in that you gave me
Fire Fire

2022/12/7

#
danpost wrote...
Copy/paste the error message here along with any relevant codes.
/**
 * Write a description of class Scroller here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Scroller extends ImageScrollWorld
{
    // instance variables - replace the example below with your own
    private [b]World[/b] world;
    private [b]GreenfootImage[/b] scrollImage;
    private boolean limited;
    private int scrolledX, scrolledY;
    private int wide, high;

    /**
     * Constructor for objects of class Scroller
     */
    public Scroller([b]World [/b]viewWorld, [b]GreenfootImage [/b]image)
    {
        world=viewWorld;
        scrollImage=image;
        if(image !=null)
        {
            wide=image.getWidth();
            high=image.getHeight();
        }
        scroll(0, 0);
    }

    public Scroller([b]World[/b] veiwWorld, [b]GreenfootImage[/b] image, int wide, int high)
    {
        this.wide=wide;
        this.high=high;
        limited=true;
        World=veiwWorld;
        if(image !=null)
        {
            [b]srollImage[/b]=new [b]GreenfootImage[/b](wide*world.getCellSize(), high*world.getCellSize());
            for(int x=0;x<wide*world.getCellSize(); x+=image.gtWidth())
                for (int y=0; y<high*world.getCellSize(); y+=image.getHeight())
                    scrollImage.drawImage(image,x,y);
            scroll(0,0);      
        }
    }

    public void scroll(int dsx, int dsy)
    {
        //adjust scroll amounts and scroll background image
        if(limited)
        {
            //calculate limits of scrolling
            int maxX=wide-world.getWidth();
            int maxY=high-world.getHieghyt();
            //apply limits to distances to scroll
            if (scrolledX+dsx<0)dsx=-scrolledX;
            if(scrolledX+dsx>=maxX) dsx=maxX-scrolledX;
            if(scrolledY+dsy<0)dsy=-scrolledY;
            if(scrolledY+dsy>=maxY)dsy=maxY-scrolledY;
            //update scroll positions
            scrolledX+=dsx;
            scrolledY+=dsy;
            //scrollbackground image
            if(scrollImage!=null)
            {
                world.getBackground().drawImage
                (
                    scrollImage,
                    -scrolledX*world.getCellSize(),
                    -scrolledY*world.getCellSize()
                );
            }
        }
        else //unlimited image wrapping
        {
            //update scroll positions
            scrolledX+=dsx;
            scrolledY+=dsy;
            //scroll background image
            if(scrollImage!=null)
            {
                //create working variables of scroll positions
                int imageX=scrolledX*world.getCellSize();
                int imageY=scrolledY*world.getCellSize();
                //get near-zero starting positions for drawing 'srollImage' onto it
                imageX=imageX%wide;
                imageY=imageY%high;
                // adjust negative values as needed
                if(imageX<0)imageX+=wide;
                if(imageY<0)imageY+=high;
                // create image of approiate size and tile fill 'scrollImage' onto it
                [b]GreenfootImage[/b] hold=new [b]GreenfootImage[/b](scrollImage);
                hold.drawImage(scrollImage, -imageX, -imageY);
                if(imageX>0)hold.drawImage(scrollImage,wide-imageX,-imageY);
                if(imageY>0)hold.drawImage(scrollImage,-imageX,high-imageY);
                if(imageX>0 && imageY>0)
                   hold.drawImage(scrollImage, wide-imageX, high-imageY);
                // set image to Background of 'world'
                world.setBackground(hold);
            }
        }
        // adjust position of all actors (that can move with 'setLocation')
        for (Object obj : world.getObjects(null))
        {
           [b] Actor[/b] actor=([b]Actor[/b])obj;
            actor.setLocation(actor.getX()-dsx, actor.getY()-dsy);
        }
    }
    
    public int getScrolledX()
    {
        return scrolledX;
    }
    
    public int getScrolledY()
    {
        return scrolledY;
    }
}
This is the scroller code from your tutorial and there is 13 Errors the code with the around it is an error message
danpost danpost

2022/12/8

#
Fire wrote...
<< Code Omitted >> This is the scroller code from your tutorial and there is 13 Errors the code with the around it is an error message
No, it is not the code of my Scroller class code. The Scroller class I wrote extends the Object class (implicitly, by not adding the extends clause). Copy/paste my Scroller class code from the appropriate link from my demo or turorial back into your project replacing what you have shown in your last post. Do not modify its codes -- ever. Make sure you get all of its code as well.
Fire Fire

2022/12/8

#
danpost wrote...
No, it is not the code of my Scroller class code. The Scroller class I wrote extends the Object class (implicitly, by not adding the extends clause). Copy/paste my Scroller class code from the appropriate link from my demo or turorial back into your project replacing what you have shown in your last post. Do not modify its codes -- ever. Make sure you get all of its code as well.
I got rid of the extend part of the code but the errors are still there it doesn't know what the world class is and this code is exectly the same no code has been changed Would changing World to MyWorld fix a couple of errors?
Spock47 Spock47

2022/12/8

#
Do you have
import greenfoot.*;
as the first line of Scroller.java? (because it is not shown in the source code you shared and it would explain why the compiler would say that it does not know "World" and "GreenfootImage")
Fire Fire

2022/12/8

#
It is and it still has errors
Spock47 Spock47

2022/12/8

#
Still the same 13 errors? Please copy/paste the error messages here for each of the errors and include the line numbers. (If multiple errors have identical error message, it is sufficient to copy it once and just tell line numbers for all occurrences of it).
Constructor Range in class Range in class Range cannot be applied to given types; required: no arguments found: boolean
This states that the definition he finds for Range constructor does not require any arguments. The source code shown in this thread has a constructor that requires a boolean. Ergo, the constructor the compiler finds is not the constructor shown in this thread. This can e.g have the following reasons: - A. The source code shown for Range class in this thread is not the source code that you were running. => Please verify that you are actually using the Range class source code from this thread. - B. The compiler found another Range class and tries to call its constructor. => 1. Check whether there are any other imports that would match the name Range (e.g. import java.util.Range) and remove them. => 2. Comment out your Range class and see whether the error message stays the same. (Don't forget to uncomment it after the test.) - C. The compilation of some classes (e.g. Range) is incomplete because of other errors, which could cause the compiler not to find the constructor although it is there. => Fix the other compiler errors first.
danpost danpost

2022/12/9

#
Fire wrote...
It is and it still has errors
Please show all the code you have in the Scroller class at this point.
Fire Fire

2022/12/9

#
danpost wrote...
Please show all the code you have in the Scroller class at this point.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Scroller here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Scroller  
{
    // instance variables - replace the example below with your own
    private int MyWorldworld;
    private GreenfootImage scrollImage;
    private boolean limited;
    private int scrolledX, scrolledY;
    private int wide, high;

    /**
     * Constructor for objects of class Scroller
     */
    public Scroller(MyWorld veiwWorld, GreenfootImage image)
    {
        world=veiwWorld;
        scrollImage=image;
        if(image!=null)
        {
            wide=image.getWidth();
            high=image.getHeight();
        }
        scroll(0,0);
    }

    public Scroller(MyWorld veiwWorld, GreenfootImage image, int wide, int high)
    {
        this.wide=wide;
        this.high=high;
        limited=true;
        world=veiwWorld;
        if(image!=null)
        {
            scrollImage= new GreenfootImage(wide*wide.getCellSize(),high*world.getCellSize());
            for (int x=0;x<wide*world.getCellSize();x+=image.getWidth())
               for(int y=0; y<high*world.getCellSize();y+=image.getHeight())
                  scrollImage.drawImage(image,x,y);
        }
    }
    
    public void scroll(int dsx,int dsy)
    {
        if(limited)
        {
            int maxX=wide-world.getWidth();
            int maxY=high-world.getHeight();
            if(scrolledX+dsx<0)dsx=-scrolledX;
            if(scrolledX+dsx>=maxX)dsx=maxX-scrolledX;
            if(scrolledY+dsy<0)dsy=-scrolledY;
            if(scrolledY+dsy>=maxY)dsy=maxY-scrolledY;
            scrolledX+=dsx;
            scrolledY+=dsy;
            if(scrollImage !=null)
            {
                World.getBackground().drawImage
                (scrollImage,
                -scrolledX*world.getCellSize(),
                -scrolledY*world.getCellSize()
                );
            }
        }
    }
}
I had to re enter the code this is what I have currently
danpost danpost

2022/12/10

#
Fire wrote...
<< Code Omitted >> I had to re enter the code this is what I have currently
Again, you have modified the code. Use the code as given from the link. Do not modify it at all. Copy it and paste it, in its entirety, into your class, replacing all codes currently in it.
Fire Fire

2022/12/13

#
danpost wrote...
Again, you have modified the code. Use the code as given from the link. Do not modify it at all. Copy it and paste it, in its entirety, into your class, replacing all codes currently in it.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Scroller here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Scroller  
{
    // instance variables - replace the example below with your own
    private int MyWorldworld;
    private GreenfootImage scrollImage;
    private boolean limited;
    private int scrolledX, scrolledY;
    private int wide, high;
    private World world;
    /**
     * Constructor for objects of class Scroller
     */
    public Scroller(World veiwWorld, GreenfootImage image)
    {
        world=veiwWorld;
        scrollImage=image;
        if(image!=null)
        {
            wide=image.getWidth();
            high=image.getHeight();
        }
        scroll(0,0);
    }

    public Scroller(World veiwWorld, GreenfootImage image, int wide, int high)
    {
        this.wide=wide;
        this.high=high;
        limited=true;
        world=veiwWorld;
        if(image!=null)
        {
            scrollImage= new GreenfootImage(wide*wide.getCellSize(),high*world.getCellSize());
            for (int x=0;x<wide*world.getCellSize();x+=image.getWidth())
                for(int y=0; y<high*world.getCellSize();y+=image.getHeight())
                    scrollImage.drawImage(image,x,y);
        }
    }

    public void scroll(int dsx,int dsy)
    {
        if(limited)
        {
            int maxX=wide-world.getWidth();
            int maxY=high-world.getHeight();
            if(scrolledX+dsx<0)dsx=-scrolledX;
            if(scrolledX+dsx>=maxX)dsx=maxX-scrolledX;
            if(scrolledY+dsy<0)dsy=-scrolledY;
            if(scrolledY+dsy>=maxY)dsy=maxY-scrolledY;
            scrolledX+=dsx;
            scrolledY+=dsy;
            if(scrollImage !=null)
            {
                World.getBackground().drawImage
                (scrollImage,
                    -scrolledX*world.getCellSize(),
                    -scrolledY*world.getCellSize()
                );
            }
        }
        else
        {
            scrolledX+=dsx;
            scrolledY+=dsy;
            if(scrollImage!=null)
            {
                int imageX=scrolledX*world.getCellSize();
                int imageY=scrolledY*world.getCellSize();
                imageX=imageX%wide;
                imageY=imageY%high;
                if(imageX<0)imageX+=wide;
                if(imageY<0)imageY+=high;
                GreenfootImage hold=new GreenfootImage(scrollImage);
                hold.drawImage(scrollImage,-imageX, -imageY);
                if(imageX>0)hold.drawImage(scrollImage,wide-imageX,-imageY);
                if(imageY>0)hold.drawImage(scrollImage,-imageX,high-imageY);
                if(imageX>0&&imageY>0)
                    hold.drawImage(scrollImage, wide-imageX, high-imageY);
                world.setBackground(hold);
            }
        }
        for(Object obj :world.getObjects(null))
        {
            Actor actor=(Actor)obj;
            actor.setLocation(actor.getX()-dsx, actor.getY()-dsy);
        }
    }
    
    public int getScrolledX()
    {
        return scrolledX;
    }
    
    public int getScrolledY()
    {
        return scrolledY;
    }
}
I have changed the code by adding on line of code to it dropping the error count from 15 to 2 that being private World world; But it doesn't know .getCellSize, .getBackground, and .getObject what would I do to potentially fix it?
Spock47 Spock47

2022/12/13

#
Fire wrote...
danpost wrote...
Again, you have modified the code. Use the code as given from the link. Do not modify it at all. Copy it and paste it, in its entirety, into your class, replacing all codes currently in it.
I have changed the code by adding on line of code to it dropping the error count from 15 to 2 that being private World world; But it doesn't know .getCellSize, .getBackground, and .getObject what would I do to potentially fix it?
I guess there are a lot more changes there than that, e.g. line 12 was surely not in the original. Your error with getCellSize is because you call it on "wide", which is an int, instead of calling it on "world". Was that in the original code? Your error with getBackground is because you call it on "World" instead of "world" (upper case / lower case differences matter). Was that in the original code? Which line is the error with getObject? I guess it will be resolved, too, if you just change back to the original code from danpost's link. Best option is to do as danpost says: just copy-paste the original code without any changes!
Fire Fire

2022/12/14

#
Spock47 wrote...
I guess there are a lot more changes there than that, e.g. line 12 was surely not in the original. Your error with getCellSize is because you call it on "wide", which is an int, instead of calling it on "world". Was that in the original code? Your error with getBackground is because you call it on "World" instead of "world" (upper case / lower case differences matter). Was that in the original code? Which line is the error with getObject? I guess it will be resolved, too, if you just change back to the original code from danpost's link. Best option is to do as danpost says: just copy-paste the original code without any changes!
It got fixed
Fire Fire

2022/12/14

#
import greenfoot.*;
/**
 * CLASS: ImageScrollWorld
 *
 * DESCRIPTION: creates a limited (to scrolling background image size) center screen actor
 * following scrolling world 
 */
public class ImageScrollWorld extends MyWorld
{
    public static final int WIDE = 600; // world width (viewport)
    public static final int HIGH = 400; // world height (viewport)
     
    Scroller scroller; // the object that performs the scrolling
    Actor scrollActor; // an actor to stay in view
    boolean roaming;
     
    public ImageScrollWorld()
    {
        [u]super[/u](600, 400, 1, false); // creates an unbounded world
        setPaintOrder(Player.class);
        GreenfootImage bg = new GreenfootImage(100, 100); // creates an image to scroll
        bg.fill();
        bg.setColor(Color.LIGHT_GRAY);
        bg.fillRect(2, 2, 96, 96);
        bg.scale(1000, 1000);
        bg.setColor(Color.DARK_GRAY);
        for (int i=100; i<1000; i+=100)
        {
            bg.drawLine(i, 0, i, 1000);
            bg.drawLine(0, i, 1000, i);
        }
        int bgWide = bg.getWidth(); // scrolling image width
        int bgHigh = bg.getHeight(); // scrolling image height
        scroller = new Scroller(this, bg, bgWide, bgHigh); // creates the Scroller object
        scrollActor = new Player(); // creates the actor to maintain view on
        addObject(scrollActor, bgWide/2, bgHigh/2); // add actor at center of scrolling area (wherever)
        addObject[u](new Range(roaming)[/u], WIDE/2, HIGH/2);
        scroll(); // sets initial background image and puts main actor in view if needed
    }
     
    public void act()
    {
        [u]checkEscape()[/u]; // to return to demo menu
        if (Greenfoot.mouseClicked(null))
        {
            roaming = !roaming;
            removeObjects(getObjects(Range.class));
            addObject[u](new Range(roaming)[/u], WIDE/2, HIGH/2);
        }
        if (scrollActor != null)
        {
            if (roaming) scroll2(); else scroll();
        }
    }
     
    // attempts scrolling when actor is not in center of visible world
    private void scroll()
    {
        // determine scrolling offsets and scroll
        int dsx = scrollActor.getX()-WIDE/2; // horizontal offset from center screen
        int dsy = scrollActor.getY()-HIGH/2; // vertical offset from center screen
        scroller.scroll(dsx, dsy);
    }
 
    // attempts scrolling when actor is outside roaming limits
    private void scroll2()
    {
        // roaming limits of actor
        int loX = 100;
        int hiX = WIDE-100;
        int loY = 50;
        int hiY = HIGH-50;
        // determine offsets and scroll
        int dsx = 0, dsy = 0;
        if (scrollActor.getX() < loX) dsx = scrollActor.getX()-loX;
        if (scrollActor.getX() > hiX) dsx = scrollActor.getX()-hiX;
        if (scrollActor.getY() < loY) dsy = scrollActor.getY()-loY;
        if (scrollActor.getY() > hiY) dsy = scrollActor.getY()-hiY;
        scroller.scroll(dsx, dsy);
    }
}
Every bit of code with the underline symbol around it is an error
There are more replies on the next page.
1
2
3