-1

Ok I have an object and a big square as well as other stuff in a room. I need the object which is obj_dot to randomly spawn but only within the big square (which is obj_paper) every time the room restarts.

user1947331
  • 47
  • 2
  • 7
  • It's very simple question. You can get answer on official gmc forum http://gmc.yoyogames.com – Dmi7ry May 22 '14 at 07:58
  • Yea I couldn't find anything there but I did use this code for random respawning but don't know what to add to make it only respawn with the square. instance_create(random(room_width),random(room_height),obj_dot) – user1947331 May 22 '14 at 15:22
  • as example, use irandom_range. like `instance_create(irandom_range(50, 100), irandom_range(30, 150, obj_dot)` – Dmi7ry May 22 '14 at 17:31

1 Answers1

0

Your question lacks detailed information on the setup of your sprites/objects, therefore this answer might not suit you 100% but hopefully it will provide you with a general idea of how to go about resolving this issue.

You probably want to put something like this within the create event for an object that is created on the room creation. I'm going to assume obj_paper is created on room creation (hence is recreated on room restart).

In the create event for obj_paper, type the following using GML.

//Assuming the sprite for obj_paper has it's x & y positioned in the center of the sprite
instance_create(irandom_range(x-sprite_width/2,x+sprite_width/2),irandom_range(y-sprite_height/2,y+sprite_width/2),obj_dot);

That should do the trick nicely.

Bazay
  • 1
  • 1