Zweites Objekt einmalig an einer bestimmten Position zerstören

  • Zweites Objekt einmalig an einer bestimmten Position zerstören

    Hallo, ich hab mal wieder ein GML Problem weil mir die richtigen Befehle fehlen für das was ich möchte.

    Es gibt ja die Befehle: position_destroy(x,y) und instance_destroy() kann ich die beiden irgendwie mischen?

    Was ich bräuchte wäre quasi der Befehl instance_destroy(Player1.x,Player1.y, object_das_zerstoert_werden_soll) den es ja so leider nicht gibt ^^ (oder doch?)

    Wege wie ein einfaches Kollisions-Event die das Objekt zerstört wenn beide aufeinander treffen, erfüllen leider nicht ihren Zweck.

    Um das ganze dann noch ein bisschen schwieriger zu gestalten wäre es mir am liebsten, wenn das Objekt nur einmal zerstört wird, auch dann, wenn es an dieser Stelle mehrfach vorhanden ist.

    Ich hab eine Zeichnung angehängt die das Ganze vielleicht etwas verständlicher macht.
    Bilder
    • Neu Bitmap.GIF

      3,58 kB, 428×296, 221 mal angesehen
  • Schon mal danke für die Antwort, allerdings muss ich das ganze noch in den Code:

    GML-Quellcode

    1. if(slotImages[slot] != 1)
    einfügen.
    Aus der GameMakerHelp weiß ich, dass ich With und If mischen kann aber er wirft mir dann ständig Symbol-expected-Error aus. Vermutlich weil ich wieder Zeichen hinsetze wo sie nicht hingehören.
  • GML-Quellcode

    1. var column, row, slot;
    2. column = ((mouse_x - xStart) div sprite_width) + 1;
    3. row = ((mouse_y - yStart) div sprite_height);
    4. slot = (row * slotsInRow) + column;
    5. // Make sure the mouse is over the inventory
    6. // The slot is within the correct bounds
    7. if(mouse_x >= xStart &&
    8. mouse_y >= yStart &&
    9. mouse_x <= xStart + (sprite_width * slotsInRow) &&
    10. mouse_y <= yStart + (sprite_height * (numberOfSlots / slotsInRow)) &&
    11. slot > 0 && slot <= numberOfSlots) {
    12. // Make sure the slot is not empty
    13. if(slotItems[slot] != 0) {
    14. Inventory_Add1(slotImages[slot]);
    15. slotItems[slot] = 0; // Empty the slot
    16. slotImages[slot] = 0; // Empty the slot's sprite
    17. if(slotImages[slot] != 1)
    18. instance_create(Player1.x, Player1.y, object292);
    19. // <- Hier soll also anstatt ein bestimmtes Objekt zu erstellen
    20. // ein bestimmtes Objeckt zerstört werden.
    21. }
    22. }
    Alles anzeigen
  • GML-Quellcode

    1. var column, row, slot;
    2. column = ((mouse_x - xStart) div sprite_width) + 1;
    3. row = ((mouse_y - yStart) div sprite_height);
    4. slot = (row * slotsInRow) + column;
    5. // Make sure the mouse is over the inventory
    6. // The slot is within the correct bounds
    7. if(mouse_x >= xStart &&
    8. mouse_y >= yStart &&
    9. mouse_x <= xStart + (sprite_width * slotsInRow) &&
    10. mouse_y <= yStart + (sprite_height * (numberOfSlots / slotsInRow)) &&
    11. slot > 0 && slot <= numberOfSlots) {
    12. // Make sure the slot is not empty
    13. if(slotItems[slot] != 0) {
    14. Inventory_Add1(slotImages[slot]);
    15. slotItems[slot] = 0; // Empty the slot
    16. slotImages[slot] = 0; // Empty the slot's sprite
    17. if(slotImages[slot] != 1)
    18. with(instance_position(Player1.x, Player1.y, object292)) {instance_destroy();} // <== geändert
    19. }
    20. }
    Alles anzeigen

    Und hier nochmal wie ich empfehle Codes zu schreiben:
    Spoiler anzeigen

    GML-Quellcode

    1. var column, row, slot;
    2. column = ((mouse_x - xStart) div sprite_width) + 1;
    3. row = ((mouse_y - yStart) div sprite_height);
    4. slot = (row * slotsInRow) + column;
    5. // Make sure the mouse is over the inventory
    6. // The slot is within the correct bounds
    7. if (mouse_x >= xStart) &&
    8. (mouse_y >= yStart) &&
    9. (mouse_x <= xStart + (sprite_width * slotsInRow)) &&
    10. (mouse_y <= yStart + (sprite_height * (numberOfSlots / slotsInRow))) &&
    11. (slot > 0) && (slot <= numberOfSlots) {
    12. // Make sure the slot is not empty
    13. if(slotItems[slot] != 0) {
    14. Inventory_Add1(slotImages[slot]);
    15. slotItems[slot] = 0; // Empty the slot
    16. slotImages[slot] = 0; // Empty the slot's sprite
    17. if(slotImages[slot] != 1) {
    18. with(instance_position(Player1.x, Player1.y, object292)) {instance_destroy();}
    19. }
    20. }
    21. }
    Alles anzeigen
  • :thumbsup: Juhuuuu! :thumbsup:
    Nein das ! war schon richtig .... aber der Sprite bzw. die Bounding-Box war nicht genau auf der Stelle wo er hingehört hat.
    Thx to everybody!
  • Benutzer online 1

    1 Besucher