How do I get spritename from its UID

Get help using Construct 2

Post » Fri Jan 16, 2015 9:40 am

Hi,
I have created a function to which I am passing sprite's UID as parameter. In the function, I want to access sprite again with the help of passed UID. Will I be able to access it?.
B
3
Posts: 7
Reputation: 191

Post » Fri Jan 16, 2015 10:02 am

https://www.scirra.com/manual/130/common-features

Read under Unique IDs (UIDs). Pick by unique ID
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jan 16, 2015 12:09 pm

Thanks....Let me clarify...Suppose there are two sprites. There is one function who does the work of resizing the sprites. What I want to do actually do is I want to resize first sprite when I pass UID of first sprite and want to resize second sprite when I pass UID of second sprite. To be more concised, I want one function to work with two different sprites.....Is it possible??
B
3
Posts: 7
Reputation: 191

Post » Fri Jan 16, 2015 1:17 pm

More info, ok :) So when you say 2 Sprites, I assume you mean 2 different object types, not 2 instances of 1 object type (Sprite) otherwise it would be no more difficult than 1. You will have to put it them in a Family then you can pick Family by unique ID.

edit: I'm ignoring that your topic title says that you want to get 'spritename' because that's not what you've asked in your questions.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Jan 19, 2015 4:29 am

Thanks....There are two different sprites.......and I am passing UID of one sprite to the function.....Like....

resize(sprite1.UID)...............(Function call)


resize(sprite1.UID)..............(Function Definition)
{
Sprite1------set size to (420,630);
}




Is it possible in construct2? If I pass sprite2 to the same function will it work?....If you did this, would you please share .capx file?
B
3
Posts: 7
Reputation: 191

Post » Mon Jan 19, 2015 4:37 am

Yes. Picking an object by UID is pretty fundamental and the link I posted above has the details.
edit: the yes is for the first part of the question. The second part is 'no', but see below for how to do it.

If you have two different sprite types then you'll need to add them to a Family, then pick Family by UID in the function.

If I get a sec I'll do a capx.

edit: hope this helps. You'll see if you select Sprite1, then try and change it's size using ResizeASprite2() function, it won't resize (same with Sprite2 and ResizeASprite1()). If you use the ResizeSpriteByFamily() function you can click either type and it will still work.
pass_uid_to_function.capx


edit: tiny update to capx so you can keep resizing until the cows come home
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Jan 19, 2015 10:48 am

Great!!!!!.....Thanks a ton....
B
3
Posts: 7
Reputation: 191

Post » Mon Jan 19, 2015 12:25 pm

chinmayk9141 wrote:Great!!!!!.....Thanks a ton....



welcome
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 36 guests