How do I count each sprite width

Get help using Construct 2

Post » Sat Apr 22, 2017 9:34 am

hello,

how in text obiect display sum of all sprites width in game?
for example when i have sprites
A - width 10
B - width 20
C - width 50
etc

text object should display 80 ?
B
10
S
2
Posts: 42
Reputation: 715

Post » Sat Apr 22, 2017 10:07 am

Hi maxwell88 one way might be:

Create a global variable e.g. totalWidth

Put all your sprites in a family e.g. allSprites

Trigger once:
>>System|For each allSprites: System|Add allSprites width to globalwidth
>>Set text on text object to globalwidth
B
20
S
9
G
4
Posts: 473
Reputation: 4,260

Post » Sat Apr 22, 2017 1:15 pm

Message: maxwell88 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
mekonbekon wrote:Hi maxwell88 one way might be:

Create a global variable e.g. totalWidth

Put all your sprites in a family e.g. allSprites

Trigger once:
>>System|For each allSprites: System|Add allSprites width to globalwidth
>>Set text on text object to globalwidth



Something dont work well, even if i add trigger once, variable counts every time to infinite

take look at capx
https://www.dropbox.com/s/ycyjvyviju9n3 ... .capx?dl=0
B
10
S
2
Posts: 42
Reputation: 715

Post » Sat Apr 22, 2017 6:03 pm

Are all the sprites one object or separate? If it is one object you can use a loop and a counter.

First set CounterVariable to 0.

Repeat Sprite.Count times - Add Sprite(loopindex).Width to CounterVariable.

Make sure the loop runs by trigger and not every tick.

If they are separate objects you should be able to do the same thing with family.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Sun Apr 23, 2017 12:47 pm

Its one object like in my attached capx

I try fix this when i return home
oosyrag wrote:Are all the sprites one object or iseparate? If it is one object you can use a loop and a counter.

First set CounterVariable to 0.

Repeat Sprite.Count times - Add Sprite(loopindex).Width to CounterVariable.

Make sure the loop runs by trigger and not every tick.

If they are separate objects you should be able to do the same thing with family.
B
10
S
2
Posts: 42
Reputation: 715

Post » Sun Apr 23, 2017 6:46 pm

@oosyrag

First set CounterVariable to 0.
you mean global variable ? or instance variable ?
B
111
S
28
G
48
Posts: 1,882
Reputation: 36,428

Post » Sun Apr 23, 2017 8:19 pm

It can be either.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Sun Apr 23, 2017 8:22 pm

oosyrag wrote:It can be either.



i make something like that, unfortunetly dont works
dropbox.com/s/c45rknmx4b99vi6/Zrzut%20ekranu%202017-04-23%2022.21.12.png
B
10
S
2
Posts: 42
Reputation: 715

Post » Mon Apr 24, 2017 1:15 am

Mistakes were made.
B
53
S
27
G
114
Posts: 1,698
Reputation: 64,444

Post » Mon Apr 24, 2017 8:36 am

oosyrag wrote:https://www.dropbox.com/s/keya08japv65wl4/totalwidth.capx?dl=0

Two ways, both work.



ok, now its possible to change width in real time not only at start?
because in my game, sprites should have posibliliy to change width size by user
B
10
S
2
Posts: 42
Reputation: 715

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 24 guests