GM: instance create
From GMpedia.org Wiki
- The correct title of this article is instance_create(x,y,obj). It appears incorrectly here because of technical restrictions.
- The correct title of this article is instance_create(). It appears incorrectly here because of technical restrictions.
Arguments
X = Horizontal position on screen in pixels. Y = Vertical position on screen in pixels. obj = The object you want to display.
Limitations
none
Note: Please remove limitations and port them in the "Remarks" section at the end of the article.
This will create an instance of <object> at position X and Y. X and Y are screen position in pixels and can be anywhere, outside the current view, even outside the physical screen size, these are especially good for creating objects that start outside the screen area and then come into view.
[edit] Example
For example, the default room size that Game Maker creates is 640 x 480, instance_create(0,0,obj_enemy) will create obj_player at the top-left hand corner of the screen, while instance_create(-100,0,obj_enemy) will create the object 100 pixels to the left outside of the current screen, this is handy if you want your enemy to 'fly in'.
You're not just limited to absolute co-ordinates (numbers), you can create an object relative to another object, e.g. say for example you wanted something to appear next to your player, no matter where on the screen he is, you could have something like:
instance_create(obj_player.x+10,obj_player.y+10,obj_fairy);
This will create the object 'obj_fairy' 10 pixels to the right and 10 pixels down from the sprites origin (default is the top-left of the sprite). You can even create objects appear at a random position on the screen:
instance_create(floor(random(room_width)), floor(random(room_height)),obj_bullethole);
See the talk page for details

