Ordering of Instance_Create

Discussion in 'Legacy GameMaker Community Tech Support' started by ProdigyProGaming, May 20, 2017.

  1. I am currently trying to make a drawing game and i am still fairly new to game maker.
    I have made it so that when the left mouse button is held, an new instance is created drawing a line.However, when working with other colours, the layering is in the order of the the code. E.g

    if Colour = 1
    {
    instance_create(mouse_x, mouse_y, objBlackColourLineSmall)
    object_set_depth(objBlackColourLineSmall, -1000)
    }
    if Colour = 2
    {
    instance_create(mouse_x, mouse_y, objRedColourLineSmall)
    object_set_depth(objRedColourLineSmall, -1000)

    objBlackLineColourSmall is alwasy on top of objRedColourLineSmall. I do not want to set the depths to different values because then they will be in a set order.
    what i want is the latest drawing to be on top regardless of what colour it is.
    thanks,
    Arron
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,241
    I believe it will work if you remove the object_set_depth(objBlackColourLineSmall, -1000) and have the depth set in the object Editors themselves both at -1000.
     
  3. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    7,070
    Setting the depth of the OBJECT is not the same as setting the depth of the INSTANCE. The new object depth will not be noticed until you create a new instance of that object. So set the "depth" variable directly like this:

    Code:
    var _inst = instance_create(mouse_x, mouse_y, objRedColourLineSmall)
    _inst.depth = -1000; 
    ;)
     
  4. Thank you, it now doesn't prioritise but how would i set it to be on top of the last created. After implementing your code, it places the selected colour to the bottom layer, underneath everything but i would like it to be on top.
    thanks
    Arron
     
  5. rytan451

    rytan451 Member

    Joined:
    Jun 21, 2016
    Posts:
    61
    A friendly note, there are better mechanisms than using instances to make the images in a drawing game. But if you wish to do so, I would recommend having a global variable set to 0, and each time you switch colors, you decrease the variable by 1. Then, when you create your colored instance, set the depth to that global variable.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice