How do I ?

Get help using Construct 2

Post » Fri May 19, 2017 4:19 pm

Hi,
i have an object that rotate 360 degress
i would play to play a sound every 5 degress
something like every that object rotate 5 degres it play that sound
how can i done it ?
thanks
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Fri May 19, 2017 4:44 pm

There are lots of ways to do this.

The following way will work if the object is spinning very slowly (less than 1 degree per tick). If it is spinning more quickly you are going to get a very erratic sound:

Condition:
System -> compare two values -> sprite.angle%5 < 1

Action:
Audio -> Play sound



For an object that is spinning more quickly, give the object an instance variable called "lastSoundAngle". When you first play a sound, set lastSoundAngle = sprite.angle. Every tick, check if abs(anglediff((sprite.Angle - lastSoundAngle)) > 5, then play the sound again and set lastSoundAngle = sprite.Angle.
www.simbucket.com - HTML5 Science Simulations / https://www.airconsole.com/#!play=com.n ... obotrumble - Robot Rumble on AirConsole
B
51
S
15
G
25
Posts: 424
Reputation: 17,321

Post » Fri May 19, 2017 5:38 pm

did not understand
an example will be appreciated
thank you
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Fri May 19, 2017 6:25 pm

any help please?
thanks in advance
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Fri May 19, 2017 7:34 pm

Here you go.

(I just used @cjbruce 's code, nothing fancy)

Btw, in case you didn't know, the % in divisions is the so called modulo operator.
In returns the rest of a division.
An example: 5 modulo 2 (5%2) would return 1, since you can put the 2 two times in the four, but you'll have one rest.
12 % 5 = 2,
66 % 10 = 6
and so on.

This is especially useful here, but generally useful, if you want to see whether a number is dividable by another number.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri May 19, 2017 7:56 pm

randomly wrote:Here you go.

(I just used @cjbruce 's code, nothing fancy)

Btw, in case you didn't know, the % in divisions is the so called modulo operator.
In returns the rest of a division.
An example: 5 modulo 2 (5%2) would return 1, since you can put the 2 two times in the four, but you'll have one rest.
12 % 5 = 2,
66 % 10 = 6
and so on.

This is especially useful here, but generally useful, if you want to see whether a number is dividable by another number.

not work as perfect
check the game link on your pm
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Fri May 19, 2017 8:32 pm

Even though there is no sound at all in the game link, I can tell you why it might not work:

The game you are creating has rotation speeds of 1000+ degrees per second.
One frame is usually rendered at 1/60 of a second.
1000/60 is ~17 degrees per second.
This means that during one frame, the audio would have been played three times already.
(And this is only for 1000 degrees per second, imagine it being 3000)
Like this, the sound would play each frame.
Since the sounds won't stop after one second, they'll overlap and cause weird noises.

You will have to step up with the 5 degrees to something like 20 or even more.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Fri May 19, 2017 9:30 pm

@randomly
viewtopic.php?f=148&t=191811
need some bug fixes about the sound but it's ok
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Sat May 20, 2017 6:02 am

The audio scheduling example included with C2 may be useful to play multiple sounds in between ticks. Just set the interval to 5/speed, where 5 is the number of degrees per sound and speed is in degrees per second of the rotation.
B
94
S
33
G
114
Posts: 5,357
Reputation: 73,775

Post » Sat May 20, 2017 2:23 pm

cannot done it :(
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests