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

2019/2/9

get backgroound of an Actor

1
2
xandreas_1 xandreas_1

2019/2/10

#
In Line 14 "new Scroller(this,image)" is underlines with the error : constructor Scroller in class Scroller cannot be applied to given type; requires: no arguements found: MyWorld, greenfoot.GreenfootImage reason: actual and formal arguement lists differ in length and in line 27 is still the same error, even I added ,0
danpost danpost

2019/2/10

#
Sounds like you have the wrong Scroller class or you modified it. Please show your Scroller class codes for review.
xandreas_1 xandreas_1

2019/2/10

#
I just have the myWorld Class. I think I need another class, dont I?
danpost danpost

2019/2/10

#
xandreas_1 wrote...
I just have the myWorld Class. I think I need another class, dont I?
You need the Scroller class. Get it here.
danpost danpost

2019/2/10

#
I fixed the link above. It took you to the correct page; but, you may have gone to the wrong post for the code. After seeing this post, go to the link and copy/paste the code it takes you to.
xandreas_1 xandreas_1

2019/2/10

#
where do I have to put in the Scroler Code
danpost danpost

2019/2/11

#
xandreas_1 wrote...
where do I have to put in the Scroler Code
In the main menu bar, select Edit>New class.... ; enter a couple miscellaneous characters for the name and accept it. Then, open to edit the new class and copy/paste the Scroller class code in it replacing everything that was in it.
xandreas_1 xandreas_1

2019/2/11

#
import greenfoot.*;

public class Scroller
{
    private World world; // view window world
    private GreenfootImage scrollImage; // scrolling image
    private boolean limited; // flag to indicate whether scrolling is limited or not
    private int scrolledX, scrolledY; // current scrolled distances
    private int wide, high; // if limited, dimensions of scrolling area else of image to wrap
    

    public Scroller(World viewWorld, GreenfootImage image)
    {
        world = viewWorld;
        scrollImage = image;
        if (image != null)
        {
            wide = image.getWidth();
            high = image.getHeight();
        }
        [u]scroll[/u](0, 0); // sets initial background image
    }
}

scroll is still underlined and it says that it doesnt know a method scroll(int/int)
    
xandreas_1 xandreas_1

2019/2/11

#

    import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MyWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MyWorld extends World
{
public static final int WIDE = 1500;
public static final int HIGH = 750;
Scroller scroller;
    
    public MyWorld()
    {    
      
    
    
        super(WIDE, HIGH, 1, false) ;
      GreenfootImage image = new    GreenfootImage("greenLandscapewithbrown1.0.jpg");
      scroller = new Scroller(this,image);
    }
    
    public void act()
    {
     scroll();   
    }
    private void scroll()
    {
     int rate = 2;
     int dsx = 0;
     if(Greenfoot.isKeyDown("W")) dsx ++;
     if(Greenfoot.isKeyDown("S")) dsx --;
     scroller[u].scroll[/u](dsx*rate, 0);
    }
    
}
here it showas the same error
danpost danpost

2019/2/11

#
Where is the rest of your Scroller class? It should be 172 lines long!!! Go back to the link and copy the entire class to replace what you have.
xandreas_1 xandreas_1

2019/2/11

#
ah thx a lot :D I didnt see the end of the code... my bad So now my world moves, but all of my Actors as well... How can I fixe it
danpost danpost

2019/2/11

#
xandreas_1 wrote...
ah thx a lot :D I didnt see the end of the code... my bad So now my world moves, but all of my Actors as well... How can I fixe it
You could comment out lines 146 through 150 in the Scroller class.
xandreas_1 xandreas_1

2019/2/11

#
thx a lot :D
You need to login to post a reply.
1
2