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

2012/11/15

adding object to a world after they are removed.

actinium actinium

2012/11/15

#
When my hero gets caught i remove all actors from the world. When i redraw the world using addObject method the world is redrawn but the hero and ghost objects are not redrawn. The only difference i can see is that the hero and ghost objects have parameters to the constructors but the other objects dont, am i missing something here.
davmac davmac

2012/11/15

#
am i missing something here
Yes, your code is missing so we can't see what's wrong with it.
actinium actinium

2012/11/15

#
 private void drawLevel()
    {
        LevelData level = new LevelData();
        int[][] ld = level.levelData(levelValue);
        map = ld;
        int offset = 25;
        int imageWidth = 50;
        int imageHeight = 50;
        
        for (int row = 0; row < 11;row++)
        {
            for (int col = 0; col < 15;col++)
            {
                if (ld[row][col]==SPACE_CELL)
                {
                    addObject(new Space(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                if (ld[row][col]==WALL_CELL)
                {
                    addObject(new Brick(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                if (ld[row][col]==KEY_CELL)
                {
                    addObject(new Key(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                if (ld[row][col]==CHEST_CELL)
                {
                    addObject(new Chest(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                
                if (ld[row][col]==DOOR_CELL)
                {
                    addObject(new Door(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                
                if (ld[row][col]==DEVIL_CELL)
                {
                    System.out.println("Devil");
                    addObject(new Devil(),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                if (ld[row][col]==HERO_CELL)
                {
                    System.out.println("hero");
                    addObject(new Hero(row,col),col*imageWidth+offset,row*imageHeight+offset);
                }
                
                if (ld[row][col]==GHOST_CELL)
                {
                    addObject(new Ghost(row,col),col*imageWidth+offset,row*imageHeight+offset);
                    setCell(row,col,SPACE_CELL);
                }
                
                
            }
        }
        
    }
    
heres the code that draws the maze. Do you need more code.
davmac davmac

2012/11/15

#
I don't see anything obviously wrong with that code; it might be worth uploading the whole scenario.
actinium actinium

2012/11/15

#
I will upload the scenario. All i want to do is reset the level when the hero bumps into a ghost.
actinium actinium

2012/11/15

#
The scenario is up davmac its called Pirates
davmac davmac

2012/11/15

#
Your LevelData class has an array which is a private static int array. You return a reference to this from the levelData(...) method, and it then gets modified. The ghost and the hero get removed from it. That's why they don't show up when you re-initialise the world. A simple fix is to make it non-static.
actinium actinium

2012/11/15

#
Thanks for taking the timeout to look at my code Davmac. I see what you mean, i will go and fix it. It is fixed, need to be carefull with the static keyword, it can mean modifying the actual memory instead of a copy, another lesson learned.
SPower SPower

2012/11/15

#
the actual memory
well, you're always changing memory, but I know what you mean :)
You need to login to post a reply.