• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Ordering of Instance_Create

P

ProdigyProGaming

Guest
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
 

Simon Gust

Member
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.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
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;
;)
 
P

ProdigyProGaming

Guest
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;
;)
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
 

rytan451

Member
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.
 
Top