How do I make an object destroy copies of itself?

  • I'm working on a drag-and-drop puzzle block game. The player toggles through the pieces available, then drag-and-drops the piece they want onto a grid.

    Now what happens is, if the player drops a piece in the wrong spot, IE out of the grid, over a differently colored piece, or on the boundary walls, it destroys the piece and creates a new one at the starting point. The same happens if the player correctly drops a piece into the grid, it creates a new piece for the player to drag around at the starting point.

    The problem I am having is that it won't delete pieces that are the same as itself!

    The player has small arrows to toggle between different shapes for, say , Red Piece. None of the red pieces will be destroyed if they are dropped on top of other red pieces. Everything else works great, but the red pieces won't destroy when dropped on other red pieces.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • because when it is destroy in line 8

    as far as i see you spawn it back with line 2

    also it seems like line 11 is not being trigger

    the only real way you can test it is to run DEBUG

  • I believe what happens is in "On RedBlock drag&drop Drop" the system picks just 1 RedBlock instance, the one you dropped.

    Then inside this event you check "If RedBlock overlapping RedBlock" and because there is only 1 instance picked, this sub-event will never be true.

    There is a simple workaround - create a family with just one RedBlock sprite, name it RedBlockFamily.

    Then you will be able to do this:

    On RedBlock drag&drop Drop
         If RedBlock overlapping RedBlockFamily
             RedBlock destroy
             RedBlockFamily destroy  // if you want to destroy both red blocks
    [/code:1az76nse]
  • Line 11 is triggering, it's what keeps the pieces that are successfully inside the grid from moving when the arrows are pressed.

    I certainly do think that families would solve this issue, and in fact, learning about families opens up lots of interesting possibilities that I have been pondering about, but, unfortunately, I don't have a license for Construct, so I guess I can't do what I'd like, haha.

  • You can do this without families. Just move event #8 from under #6, to make it top-level event.

    Add a condition "RedBlock is NOT dragging".

    The only problem is that both overlapping redblocks will be destroyed. If you want to destroy only the dropped one, you can do something like this:

    Redblock on drag start -> Move to top of layer
    
    Redblock on Drop -> (all your other checks)
    
    Redblock is overlapping Redblock
    Redblock is NOT dragging
        Redblock pick top  -> Redblock destroy
    [/code:3l68wi0x]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)