How do I create spritefont based on its uid

Get help using Construct 2

Post » Sat Dec 19, 2015 2:40 am

Hi, there
I use system create object to create spritefont, as i have two spritefonts named font which I copied not cloned,(uid:1 and uid:2), every time when I create object the font, it always create uid:1, so How can I pick the uid 2 to create. when I use pick font instance with uid:2, it not works. please help
B
11
S
3
Posts: 172
Reputation: 1,178

Post » Sat Dec 19, 2015 3:18 am

Uid is based on the order in which all objects are created, so it can not be used to create instances.
To pick an object outside of its creation event you have to use something specific to that object.
A variable works nice for that.
You can give an instance an identifier in its variable at its creation.
Image ImageImage
B
169
S
50
G
173
Posts: 8,313
Reputation: 110,270

Post » Sat Dec 19, 2015 3:48 am

You can use the .asJSON expression and the "load from json" action to copy one object to another. For example if you want to create a Sprite that is a copy of the Sprite with a uid of 2 you could do the following.

Global text template=""

On click
Pick Sprite by uid 2
--- set template to Sprite.asJSON
--- create Sprite at (0,0)
--- Sprite: load from json template
--- Sprite: set position to (mouse.x, mouse.y)
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Mon Dec 21, 2015 8:11 am

thanks @R0J0hound & @newt , seems it's not that easy to pick the instance, so I use another ways, thanks again
B
11
S
3
Posts: 172
Reputation: 1,178

Post » Sat Feb 27, 2016 9:41 pm

My solution would be to give the SpriteFont an instance variable.
Then system > compare instance variable > SpriteFont > Variable = 1 | SpriteFont > set text

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707


Return to How do I....?

Who is online

Users browsing this forum: adventurist, Artcadev, Blendi1223, PROxMTswatTR, ST314 and 29 guests