Reuse the font sprite graphics on more than one text

Discussion and feedback on Construct 2

Post » Tue Feb 03, 2015 10:14 pm

Hi.

Maybe a stupid question.
But I have a few texts shown on the layout. Each text use the same spritefont.
But I have to attache the same spritefont.png to each sprite, and I can see on the status bare that the size of the game increases for each sprite I add the same spritefont to.

Is there a way where you can reuse the same spritefont.png file for more than one spritefont sprite? To save ressources and keep the game as small as possible, but also to make it easier if I want to change the sprite font to a different font, so I do not have to alter each sprite manually.
B
5
S
1
Posts: 59
Reputation: 493

Post » Tue Feb 03, 2015 10:18 pm

Use the same spritefont and make a new instance of it. I haven't done so myself but I need to do so. I guess for static text it will work.. Of course someone here will chip in with better solution.. But maybe identify by variable?
Last edited by helena on Tue Feb 03, 2015 10:20 pm, edited 1 time in total.
B
56
S
18
G
13
Posts: 447
Reputation: 10,665

Post » Tue Feb 03, 2015 10:19 pm

you should just use one Spritefont object if they are all the same font. then if you need the font to change at runtime just assign a variable like @helena said. It works this is how i change font in all my games

Edit: beaten
B
42
S
17
G
2
Posts: 850
Reputation: 6,209

Post » Tue Feb 03, 2015 10:49 pm

If I only have one spritefont.

How can I place 4 different texts on 4 different positions in the layout, without having 4 instances?
B
5
S
1
Posts: 59
Reputation: 493

Post » Tue Feb 03, 2015 10:53 pm

@hgr you can't. 4 different texts will always work out to be 4 different instances unless you wanna do some crazy and extensive math to fit all 4 texts in instance, which is a bad idea.

So yeah, just go with the other suggestions. You will need to create 4 different instances.
ImageImageImageImage
B
54
S
19
G
51
Posts: 633
Reputation: 30,596

Post » Tue Feb 03, 2015 11:19 pm

Maybe instances has been mixed up with objects?

instance = copies of one object. (= only one sprite sheet is used)
B
56
S
18
G
13
Posts: 447
Reputation: 10,665

Post » Wed Feb 04, 2015 12:05 am

One SpriteFont with instance variable.

As was stated, you will have to have multiple instances of your single SriteFont object. The number of instances would vary depending on needs.

Just a quick example:

4 instances of said SpriteFont with different variable values for each instance.

SpriteFont | is on screen
Variable = 1 | set text to "this is instance 1"
Variable = 2 | set text to "this is instance 2"
Variable = 3 | set text to "this is instance 3"
Variable = 4 | set text to "this is instance 4"
Image Image Image
B
60
S
19
G
6
Posts: 325
Reputation: 7,915

Post » Wed Feb 04, 2015 12:17 am

I think Helena nails the problem. Sounds like the OP is confusing instance and Object. As once you create the Object and set the Sprite to the right font. your only drag and Drop or Ctrl+c/v for new instances of that object.
B
88
S
18
G
9
Posts: 2,455
Reputation: 14,928

Post » Wed Feb 04, 2015 1:41 am

And if you think it is too confusing to update and keep track of the variables, an alternative is to make the sprite font png just 0-9 for the score numbers. It at least will make the png file a tiny bit smaller. :)

Then you can use individual objects with only 0-9 for the number keeping and then a object with full character set for making instances with texts. (for dialog, info messages)
B
56
S
18
G
13
Posts: 447
Reputation: 10,665

Post » Wed Feb 04, 2015 11:04 pm

Ok thanks.

So just to be crystal clear.

If I copy an instance of a sprite font object. And I change the graphics on either one of them, it will update the graphics on all instances it has been copied from?

:-)
B
5
S
1
Posts: 59
Reputation: 493

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests