Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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