1
\$\begingroup\$

I have an object A and an object B, I want that when object B is in a certain position, the sprite of object A changes to that corresponding to that position, how do I change the sprite of object A from the script of object b?

The image may give them an idea of what I want to do, object B is the glove, And the object A is the viewer.

Tansk form any help.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

If you have only one instance of the object A then you can use with statement or object's name:

with objA
{
    sprite_index = YourSprite;
}

or

objA.sprite_index = YourSprite;

It won't work when you have more than one instance of the object A (then all instances will be changed). In this case you can use the name of the instance (press RMB on the instance in the room editor and select Copy Instance Name (also you can rename it). Then code will be like this:

inst_FD70AA4D.sprite_index = YourSprite;

or

inst_YourName.sprite_index = YourSprite;

There are couple examples:

using instance's creation code (if you don't understand what it is, check the documentation (see Creation Code).

using automatic creation

I made it lot time ago in GM8, you can just import them to GMS.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.