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

2018/6/10

How can i access a World from neither an Actor nor a World

MrCaspar MrCaspar

2018/6/10

#
This is the class EnemySpawn which should call every few seconds a method in a world:
public class EnemySpawn  
{

    public EnemySpawn(World pWorld)
    {
        pWorld.addEnemy2();
        try {
            Thread.currentThread().sleep(41);
        }
        catch(InterruptedException ie){

        }
    }
}
If i write
    public EnemySpawn()
    {
        ((GameWorld1)).addEnemy2();
I get the "non-static method from static context" error. Any Ideas?
danpost danpost

2018/6/10

#
MrCaspar wrote...
How can i access a World from neither an Actor nor a World
Change line 6 to:
((GameWorld1)pWorld).addEnemy2();
MrCaspar MrCaspar

2018/6/10

#
Doesn't find World as class in line 4
MrCaspar MrCaspar

2018/6/10

#
Ah ok works now:
public class EnemySpawn  
{

    public EnemySpawn(GameWorld1 pWorld)
    {
        ((GameWorld1)pWorld) .addEnemy2();
            try {
                Thread.currentThread().sleep(41);
            }
            catch(InterruptedException ie){
                
            }
    }
}
You need to login to post a reply.