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

2013/10/24

Scrolling Super World errors

Baenefin Baenefin

2013/10/24

#
Hello all, I have been trying to implement danposts Scrolling Super World in my game. I get an error in danposts code for some reason (I have not altered it) so I must have made an error in my other code. Here is my subclass of SWorld
import greenfoot.*;  // 

public class Level1 extends SWorld
{

    public Level1()
    {    
        this (new Alice());
    }

    public Level1(Alice alice)
    {    
        super(600, 400, 1, 1000); 

        //Player
        setMainActor(new Alice(),300,200);
        mainActor.setLocation(10, 340);
        
        //Background
        GreenfootImage bg = new GreenfootImage("Test.jpg");
        setScrollingBackground(bg);

        //Counter
        addObject(new Score(), 30, 10, false);
        addObject(new ShroomScore(), 130, 10, false);

        //Level blocks
        for(int i=1;i<30;i++)
        {
            addObject(new Block(), i*30-15, 384, true);
        }
        

        // objects
        addObject(new Heart(),400,350, true);
        addObject(new Barrel(),200,350, true);
        addObject(new Shroom(), 250,300, true);

        //Enemy
        addObject(new Walker(),600,350, true);

        //Detector
        addObject(new RDetector(), 700,350, true);
        addObject(new LDetector(), 500,350, true);
        addObject(new LevelDetect(), 795, 400, true);

    }

}
When I compile SWorld gives me an error
        for(Object obj : genActors)
        {
            Actor actor=(Actor)obj;
            actor.setLocation(actor.getX()+dxSum, actor.getY()+dySum);
        }
Greenfoot Error wrote...
incompatible types (genActors is highlighted red)
So either I have not fully understood what to do and made a mistake somewhere or... no that seems likely. So does anybody have any idea's?
Gevater_Tod4711 Gevater_Tod4711

2013/10/24

#
You probably have a class called Object in your scenario right? Object in SWorld means java.lang.Object but this is not declared explicid. So now because of your class Object the compiler wants to use the nearest class Object which is not java.lang.Object anymore. If you change line 1 in the for loop to:
if (java.lang.Object obj : genActors)
it should work.
Baenefin Baenefin

2013/10/24

#
Thank you Gevater_Tod4711, That did fix the problem indeed. I need to remember that i have to define everything and if 2 seperate things have the same definition, it won't work.
You need to login to post a reply.