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

Get help using Construct 2

Post » Thu Oct 15, 2015 1:19 pm

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 ?
Last edited by UpendraWatwe on Thu Oct 15, 2015 2:07 pm, edited 1 time in total.
B
6
Posts: 16
Reputation: 296

Post » Thu Oct 15, 2015 1:30 pm

@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...
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Oct 15, 2015 2:08 pm

Thanks @AllanR , I will try out the UID and IID suggestions you gave.
How do I select the objects by UID ?
B
6
Posts: 16
Reputation: 296

Post » Thu Oct 15, 2015 2:55 pm

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)"
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Oct 15, 2015 3:21 pm

@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"
B
6
Posts: 16
Reputation: 296

Post » Thu Oct 15, 2015 3:25 pm

@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 ?
B
6
Posts: 16
Reputation: 296

Post » Thu Oct 15, 2015 3:34 pm

@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.
B
95
S
33
G
20
Posts: 438
Reputation: 17,640

Post » Thu Oct 15, 2015 3:57 pm

@AllanR Thanks a ton.. You really helped me solve a HUGE issue. !!! Take a bow.
B
6
Posts: 16
Reputation: 296


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 15 guests