How do I select the sprite coordinates by the sprite instance variable?

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi!

    I have 5 sprites all named the same: Sprite1 but each of it has an instance variable with a different value ("Val"=1,2,3,4,5).

    How do I get the coordinates of Sprite1 by an instance variable value Val=3 to set the position of another sprite (Sprite2)?

    I need help )))

  • Pick Sprite1 object and compare variable, val=3. This would pick all instances that are val=3 but hopefully it's just one that is true? With this picked, in the same event you can set 2 local variables to the value sprite1.x and sprite1.y and there you have the co-ordinates.

  • Thanks! Good idea!

    "it's just one that is true?" fortunately yes )))

    I thought that it could be done via "set position" by something like: Sprite1.Val=3.X or Sprite1.X(Val=3).

    I thought that there would be an elegant solution in one line :)

  • You have a problem because you need to pick sprite 2 in this case, so after grabbing co-ords you need to set position of a sprite 2 if I'm understanding it correctly. For this you need to run the co-ords through a function anyway, or make a second event. Unless sprite 2 is already known somehow then you can pick the correct instance at the start of the event with sprite 1. You could do it in one event in theory which is efficient.

  • Yes, you understand it correctly )

    But... I hoped that it could be like in "set position"to Sprite2:

    X: Sprite1.X

    Y: Sprite1.Y

    and I thought that I could add some text to it like this:

    X: Sprite1.X(Val=1)

    Y: Sprite1.Y(Val=1)

    or something like that)))

  • Yeah you mentioned co-ordinates but now I think about it you can just use set position? Pick sprite 1 where val=3, sprite 2 set position to sprite 1.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks! I will try this. I think it must be working 👍

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)