I may be stupid, but how cycles work in Construct?

Get help using Construct 2

Post » Sat Jan 28, 2012 5:52 pm

I made a cycle inside the On start of layout.

Repeat 100 times
- Wait 1.0 Seconds
- Add 1 to Variable

It waits one second, then Variable goes to 100 immediately.

In my mind it should go from 1 to 100 in 100 seconds! Why it doesn't do this?

Thank you
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Jan 28, 2012 5:56 pm

another victim to the WAIT Warrior

Wait in loops is a very different "thing" - but maybe, one of the wise people will explain that. Even I have not fully understood the way it works. All I know, it works not the way one expects it...Weishaupt2012-01-28 17:56:40
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sat Jan 28, 2012 6:07 pm

So this lead to the next version, what is the correct way to "animate" a sprite from opacity 0 to opacity 100?

Thank you Weishaupt
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sat Jan 28, 2012 6:09 pm

You should use events like "every tick" or "every x seconds" to update a "countervariable" that then sets the opacity
B
42
S
19
G
12
Posts: 723
Reputation: 13,911

Post » Sat Jan 28, 2012 6:11 pm

A loop (repeat, for, for each) happens in a single tick (in a single tick, the actions get repeated as many times as required).

The wait 1 second action will delay the execution of the "add 1" action without blocking the rest of the execution of the page (and so the rest of the loop too).

Here if what you want is for 100 seconds, each second add 1 to the variable, then what you need it to "wait loopindex seconds".
For each iteration of the loop, it will wait more and more (according to the loopindex which is the current iteration of your loop).


Oh, and for a fadeout of opacity, you should rather use lerp(object.opacity, 0, 0.5*dt) (the object will disappear in a second)Kyatric2012-01-28 18:13:04
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jan 28, 2012 10:23 pm

[QUOTE=0plus1] So this lead to the next version, what is the correct way to "animate" a sprite from opacity 0 to opacity 100?[/QUOTE]
Try the Fade behavior.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Sat Jan 28, 2012 11:59 pm

Ok, forgetting the fade beahaviour, if I wanted to make a sprite disappear in a second by reducing it's height width, or any other kind of transformation, what is the correct way to do it?

Thanks
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Sun Jan 29, 2012 12:12 am

I would have done something like this.


VariableStart = 0
VariableA = 0

If SpriteA collides with SpriteB
Then VariableStart = 1

If VariableStart = 1
Every 1.0 seconds VariableA = VariableA +1

Then you could add conditions...

If VariableA => 100
then VariableA = 100
then VariableStart = 0

If VariableStart = 0
then VariableA = 0

Or something like that, but hey i sometimes go the long way around... Not been on C2 for a month or so, so there's probably new and better ways to do this.

You can just change it around to use SpriteWidth = 100 and SpriteHeight = 100 or whatever your size is, then deduct from them.


VARIABLES

SpriteWidth = 100
SpriteHeight = 100
SpriteShrink = 0

EVENTS

Setting the SpriteA Size to the variables
SpriteA width = SpriteWidth
SpriteA height = SpriteHeight

Turning the Variable SpriteShrink to 1 or ON
On Collision SpriteA with SpriteB
SpriteShrink = 1

Every 1 Second Deducting from the Width & Height Variables
If SpriteShrink =1
Every 1.0 Seconds
SpriteWidth = SpriteWidth -1
   SpriteHeight = SpriteHeight - 1

Destroying the SpriteA when size is 0 and resseting the SpriteShrink Variable
If SpriteWidth =< 0
    SpriteHeight =< 0
     Destroy SpriteA
      SpriteShrink = 0

It can be used to Rotate, Scale or any other thing you want to do. Hope you understand it... i come from a C++ background years ago so i approach things like this.

You can change the Every 1.0 Seconds to Every 0.01 this will make it go alot faster and last for about 1 Second, But you will need to know your Sprites Width and Height and work it out from there.tonycrew2012-01-29 00:39:11
B
40
S
14
G
11
Posts: 243
Reputation: 9,432

Post » Sun Jan 29, 2012 2:24 am

[code]
Object is ToDisappear
-> Object.width = lerp(object.width, 0, 0.5)
-> Object.Height = lerp(object.height, 0, 0.5)

Object.width = 0
Object.height = 0
-> Destroy Object
[/code]

Where ToDisappear is a boolean instance variable that you turned to true.Kyatric2012-01-29 02:25:11
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Jan 30, 2012 1:40 pm

[QUOTE=Weishaupt] You should use events like "every tick" or "every x seconds" to update a "countervariable" that then sets the opacity[/QUOTE]

I tried to figure ticks on my own but not seem to yet. What is the approximate duration of a tick? One (1 tick) seems to not even execute but putting the tick on 2 does not ever execute the next command.

Thanks.
B
5
S
1
G
1
Posts: 157
Reputation: 1,219

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Magistross, mallorcaredes, zatyka and 23 guests