Object.SetView and linked frame sounds problem

Started by Crimson Wizard, Sun 23/07/2023 02:38:24

Previous topic - Next topic

Crimson Wizard

There's a peculiar problem that I'm currently trying to solve.

Historically object's animation in AGS is designed so that you have to call Object.SetView first in order to assign a view, and only then Animate in order to begin animation.

This is in a way similar to Character's LockView/Animate pair, but there's a caveat: for some reason, unlike Character.LockView, Object.SetView also triggers a linked sound frame, while for Character this is only done when Animation starts.

I don't know if this is intentional or not. This may be related to Object.SetView internally passing to an older function called SetObjectFrame, which possibly could have been used as a step-by-step replacement to animation in older versions of AGS.

But this behavior conflicts with Animate, because apparently, a pair of SetView/Animate will cause 2 frames, or same frame to be processed 2 times in a quick succession. By "processed" I mean anything related to the frame's activation. Currently this is playing a linked sound.

To clarify: if you have a sound linked to a frame 0 of the given loop, then setting object to that frame with SetView, and then calling Animate will play that sound twice. Normally we do not notice that because the sounds will play in sync. But it may be found out if you print the state of AudioChannels somewhere in real time.

With the addition of "volume" parameter to Animate() function in 3.6.0 this issue becomes more complicated, because user may want to animate an object with one volume, but SetView will play it with a full volume.

At first I thought that adding AnimationVolume property to Object will solve this (similar to one added to Character type), but then realized that this does not solve this logical conflict between SetView and Animate at all: because both object's AnimationVolume and current Animate's vol param are relative factors that are consecutively applied to the default volume (i.e.: final_volume = 100% * AnimationVolume % * current Animate's volume %). As a result SetView will play a sound with one volume (not yet affected by Animate's parameter), while the rest of the frames will be once again played with other volume.
The only way to mitigate this would be to always run Animate with volume param = 100, which effectively makes this parameter useless...

To summarize this conflict:
- You must call SetView if you want to Animate an object;
- At the same time calling SetView processes the current frame's behavior regardless of whether you are planning to animate or not.

I'd like to find some solution for this, because it's wrong and annoying. Ideally this solution should be something applicable to the 3.6.1 release, as it's already causing trouble to users (this is how I found this problem).

Crimson Wizard

I wonder if a solution here is as trivial as to disable frame processing at Object.SetView, while keeping legacy SetObjectFrame behavior.

It's curious to note that Character.LockViewFrame does not process the frame's behavior (that is - does not play frame sounds). Only Character.Animate does.

SMF spam blocked by CleanTalk