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

2017/7/4

Breakout: if a special block is hit, replace it with a normal one

Actor block1 = getOneIntersectingObject(Block1.class);      
        if (block1 != null) {
            dy = -dy;

            if (dy > 0) {
                dy += 2;
            }else if (dy < 0) {
                dy -= 2;
            }

            addToScore(20);

            int altX = block1.getX();
            int altY = block1.getY();

            this.removeTouching(Block1.class);

            getWorld().addObject(new Block(), altX, altY);
        }
In the last line you can see my failed attempt trying to add a normal(just "Block") at the same position as the special one("Block1") which got hit and removed. Why doesnt it work? I collect the x and y position of the special block and refer to the current world to add a normal block at these coords...
danpost danpost

2017/7/4

#
The code given looks okay from what I can tell. Maybe it just appears to not be replacing the block1 because one act later the new block is removed because of intersecting.
ty ill check ;)
You need to login to post a reply.