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

2019/5/31

making several rows of enemys in (myWorld) without getX() ???

Im trying to spawn several enemys but my problem is that only 1 row spawns and even if i change the y coordinate in the second one If() they spawn on the edges, so 9 of them spawn although u can clearly see its +xss which means they should after 1 spawned move about 30 pixels on the x axes in one direction
private void prepare()
    {

        Player player = new Player();
        addObject(player,1,1);
        player.setLocation(296,788);
        int xs = 0;
        int xss = 0;
        for(int i = 0; i < 10; i++){             
            xs = xs + 50;
            Invader invader = new Invader();
            addObject(invader,345,366);
            invader.setLocation(1+xs,363);
        }
        for(int i = 0; i < 10; i++){             
            xss = xss + 1;
            Invader invader = new Invader();
            addObject(invader,345,366);
            invader.setLocation(1+xss,393);
        }
    }
I thought i could just use another if() inside the for() and as soon as they reached a certain x position they would change the Y coordinate +20 . but getX() is not possible in (myWorld)
danpost danpost

2019/5/31

#
Line 16 is only making a 1-pixel difference in their positions in the second row.
You need to login to post a reply.