• 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!

GML Visual Spawn objects from middle top of a object

T

tidlon

Guest
Hi I am kind of new to programming and I am trying to make cubes spawn randomly from center top of an object/sprite, so this is what I currently have...


and here is the code for the object that I want to spawn...


but it end up spawning the cubes a bit to the right of the object and not in the middle of the object as I want it to... like this
https://i.gyazo.com/4a3c1a777597026b9db05faaebd6a36a.mp4

please help.. how do I make it so the cubes spawn in the middle of the actual object (the object is the grid in the middle)
 
T

TinyGamesLab

Guest
Just uncheck the relative position of the X on the create event.
 

TheouAegis

Member
You are spawning over a grid, so set the coordinates to the grid. Set the x coordinate to

(width of the lines + 158) * irandom(4)


...edit: Wait, why is your spawning object using a sprite 299 pixels wide and the SynthNote is 158 pixels wide?Of you have multiple spawning objects, then why use random x coordinates?

Also, random() uses decimals. You almost never need or even want decimals, so use irandom().
 
Last edited:
T

tidlon

Guest
Thanks for the help, the problem was the DnD create instance, once I used GML instead it worked perfectly, it now spawns from the exact middle of the object which I wanted it to, seems like its a bug with the DnD create instance..
 

TheouAegis

Member
It's probably because you had relative checked. Also, I wasn't paying attention when I commented last time, but the value you put in y is just the object index. so the object index relative to the y-coordinate is slightly off-center because the object index is greater than 0 apparently. using the D&D, if you had just put 0 for y, you should have been fine.
 
Top