How do I make only one instance of a sprite animate or flash

0 favourites
  • 8 posts
From the Asset Store
A collection of 10 amazing sprite sheet animations for your incredible games
  • I have a set of 50 or so images organised in 10 layouts with 5 animation frames shown as separate images on each layout.

    I want to flash, increase the scale and animate the specific sprite that is tapped / clicked by the user.

    I have already done it by repeating the same set of events / actions on each event sheet, but thats making the whole project bulky . I wanted to use includes and functions so I can write on first event sheet and repeat that on each of the next event sheets.

    but when I did that all of the 5 images shown on the screen start flashing, scaling and animating.

    --

    Here is what I have tried.

    I set an instance variable "instanceIndex" for each image sprite and gave them numbers 1, through 5.

    On the individual event sheets, I save the value of "InstanceIndex" to a global variable "selectedInstance" and then call a function passing it the parameter sprite.InstanceIndex.

    However the values that I set in "InstanceIndex" are not getting saved to global variable (i also showed it as the text in a text box). The text box and "SelectedInstance" keep getting set to "0"..

    https://goo.gl/photos/x69enV1WB2Jyb6nWA

    https://goo.gl/photos/P4RnYqLkygarH1FK7

    https://goo.gl/photos/kWW5Ze7JTvkc4MLo7

    What may I be doing wrong ?

  • UpendraWatwe

    you don't need an instance variable to do this - they already have an instance ID (called IID) and you can also use their unique ID (or UID).

    You also don't really need the global variable. If the sprites are all instances of the same object you can use IID, or if they can be different objects that are part of a family you should use UID. UID is a direct link to the object that stays constant. IID is relative to how many instances there are and can change as you create or destroy instances - so I usually use UID to avoid confusion.

    You will only need one event checking if the object (or family) has been touched. Then call your function and pass object.UID as a parameter.

    In the function, the first thing you do is pick the object by UID, then you can do whatever you want to it...

  • Thanks AllanR , I will try out the UID and IID suggestions you gave.

    How do I select the objects by UID ?

  • add an event for the sprite/object you want, scroll down and look under the "Misc" section, look for "Pick by unique ID"

    if you are picking it inside a function, (and passed the UID as a parameter) then you would give it the value "function.param(0)"

  • AllanR I dont see "Pick By Unique ID" under "Misc" when I add event for the image sprite.

    I see "destroy" "set from JSON" "Set Collisions Enabled" and "Spawn another object"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • AllanR I am using the "sprite" object to create the images and loading the images by breaking a larger image into image sprites.

    Should I set the image from individual separate files ?

  • UpendraWatwe

    You are in the "add action" window... you need to do it a level higher - under "add event".

    it shouldn't matter how you break up the image... but if you have multiple sprite objects with different names, and only want one set of functions to handle everything, then you would want to put the different sprite objects in a family.

  • AllanR Thanks a ton.. You really helped me solve a HUGE issue. !!! Take a bow.

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