"Blöckr" setzen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Sieh dir mal die Funktion move_snap an.
    Ich zitiere aus der Hilfe:

    Snaps the player to the nearest position on a grid with cells of a given size. Syntax:move_snap( hsnap, vsnap );
    Returns: N/A

    Description: This function is used to "snap" the instance to a grid of a given size. It will be snapped to the nearest corresponding position on the "invisible" grid that the hsnap and vsnap values define.

    Example:

    GML-Quellcode

    1. with (obj_Pieces)
    2. {
    3. if !place_snapped(32, 32)
    4. {
    5. move_snap(32, 32);
    6. }
    7. }


    The above code checks all instances of "obj_Pieces" to see if they are snapped to a grid of 32x32 pixels, and if they are not it snaps them to the nearest position in that grid.

    Alternativ dazu kannst du z.B. nach dem Setzen die Koordinaten von Hand anpassen im Create-Event:

    GML-Quellcode

    1. x = x div 32 * 32;
    2. y = y div 32 * 32;

    div ist eine ganzzahlige Division.

    In dem Fall würde 31 (nehmen wir mal als Koordinate an) div 32 0 ergeben, weil der Kommateil abgeschnitten wird,
    33 div 32 würde 1 ergeben, ab 64 käme als Ergebnis 2 raus, usw.
    Die Methode lässt sich so ähnlich natürlich auch beim Drawen verwenden, wenn du eine Vorschau brauchst wo der Block genau gesetzt wird.