SOLVED Unable to place a X & Y room coordinate to an object

flyinian

Member
Object1 will spawn correctly, while object2 won't be affected by the given coordinates given in its create event.

Object2 will remain at the x & y coordinates that it has in the room editor.

I have many other object using this system and it seems to work fine.

I gave object2 coordinates of my UI background and it seemed to spawn at the right location.

I made a new project and tested this and same results happened.


object1:

create:

GML:
x = 0;
y = 0;
Draw:

GML:
draw_sprite(spr_Placeholder1, 0, object1.x, object1.y);


object2:

Create:

GML:
x = object1.x + 10;
y = object1.y + 10;
Draw:

GML:
draw_sprite(spr_Placeholder2, 0, object2.x, object2.y);
Thank You.
 
Last edited:

Let's Clone

Member
When is object2 being created? I assume that i's being created after object1 but, if I'm understanding you correctly, it seems like object2's create event isn't identifying where object1 is?
 

flyinian

Member
When is object2 being created? I assume that i's being created after object1 but, if I'm understanding you correctly, it seems like object2's create event isn't identifying where object1 is?

Object2 should be created after object1.

What could cause the identity crisis?
 

flyinian

Member
I may just go with a work around using instance_create_depth, but i'd like to know what causes the issue I mentioned in OP. I have other objects using that same exact method and all is good....
 

flyinian

Member
so, I stuck object1 on the very top of the creation order in the room. It now seems to work correctly. Why is this?

I had object1 directly above object2, which should mean that object1 is created before object2, right?

How come my other objects don't have issues when the object that they all spawn to is created way after all of those objects?
 

chamaeleon

Member
so, I stuck object1 on the very top of the creation order in the room. It now seems to work correctly. Why is this?

I had object1 directly above object2, which should mean that object1 is created before object2, right?

How come my other objects don't have issues when the object that they all spawn to is created way after all of those objects?
Objects don't have a creation order, instances do. Having said that, there are only one instance of object1 and object2 respectively placed in the room editor, and it is the order of instances that you are changing?
 
The order in which the code runs is up to down. You'll want to ensure the create event for the dependent objects are set AFTER the main objects. I also find it a bit odd that the sprite creation of an object seems to be set from another object when you could just draw that same sprite on the object you wanted. I think that would be a much more direct approach but maybe I don't entirely understand what it is you're trying to accomplish.

It looks like you're using some redundant code. For example, if the sprite used in object2 is being used remotely as 'object2.x' and 'object2.y'. It's already on object2, so it should be written as x and y.

Object2 is created at Object1's relative x and y coordinates but that's it. Object 2 does not follow Object1's coordinates because the placement was only set in the Create Event. I think if you want that object to be exactly at Object1's relative x and y coordinates, you'd also need to put this in the step event:

GML:
x = object1.x + 10;
y = object1.y + 10;
 

flyinian

Member
I just need the X & Y values to be placed once since they don't move in the room.

I can't get the instance to be placed to the correct X & Y position. The sprite is placed at the correct location.

Create event:

GML:
x = object1.x;
y = object1.y - 21;
Draw event:

GML:
draw_sprite(spr_Placeholder, 0, object1.x, object1.y - 21);
 

flyinian

Member
After trying different things, I think I figured out a fix. If I delete the instances with the issues and place back into the room, it fixes the issues. I'll be doing more testing to see if I actually have fixed my issue.,



edit: So, if I change the coordinates within the object the instance wont be placed correctly unless I delete the instance in the room and place it back into the room. I don't understand this but, I did find a fix.
Could this be an issue with instances placed on top of each other?

Thanks for the help, everyone.
 
Last edited:
Top