Author Topic: Transition from a Background to another  (Read 948 times)

Transition from a Background to another
« on: 06 Nov 2017, 21:36 »
The code bellow is suposed to transition from a BackGround to another.... but its not working like expected

Code: Adventure Game Studio
  1. function setBlur (bool bBlur)
  2. {
  3.   DrawingSurface* mainBackground  = Room.GetDrawingSurfaceForBackground();
  4.   DrawingSurface* newBackground;
  5.  
  6.   if (bBlur) {
  7.     newBackground = Room.GetDrawingSurfaceForBackground(2); // Blur
  8.   } else {
  9.     newBackground = Room.GetDrawingSurfaceForBackground(1); // Clear
  10.   }
  11.  
  12.   int i = 99;
  13.   while ( i > 0 )
  14.   {
  15.     mainBackground = Room.GetDrawingSurfaceForBackground();
  16.     mainBackground.DrawSurface(newBackground, i);
  17.     i --;
  18.     Wait(1);
  19.     mainBackground.Release();
  20.   }
  21. }
  22.  

To test i added the bellow options to on_key_press
Code: Adventure Game Studio
  1.   if (keycode == eKey0) setBlur(true);
  2.   if (keycode == eKey1) setBlur(false);
  3.  

1st time i hit 0 works OK but from then on seems i have to hit 1 or 0 a number of times before it execute setBlur again :(

What am i doing wrong???

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Transition from a Background to another
« Reply #1 on: 07 Nov 2017, 11:03 »
Just to get it out of the way: you would need to hit 0, then 1, then 0, then 1, etc to see the transition each time.
Hitting 0 multiple times should block the game though; can you see the wait cursor when you hit a key that supposedly does nothing?

Re: Transition from a Background to another
« Reply #2 on: 07 Nov 2017, 13:46 »
Yes the Logic would be to hit 0 then 1 then 0 then 1.... :)
The problem is that i hit 0 and runs OK, but after that the keys dont work and i have to hit them several Times before ir works..
..

dayowlron

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
Re: Transition from a Background to another
« Reply #3 on: 07 Nov 2017, 14:58 »
Just a shot in the dark. Are you waiting a few seconds between hitting the key, because with the counter at 99 the function would process for about 3 seconds before it would allow the key again.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Transition from a Background to another
« Reply #4 on: 07 Nov 2017, 15:05 »
Ok, but the most important question in my post went unanswered:
can you see the wait cursor when you hit a key that supposedly does nothing?

Your code will block the game for 2.5 seconds, assuming you didn't change the default speed of 40 FPS.

After that, keypresses should be processed fine again. So: can you see the wait cursor? Do you have a wait cursor set up?

Re: Transition from a Background to another
« Reply #5 on: 07 Nov 2017, 20:11 »
Just to get it out of the way: you would need to hit 0, then 1, then 0, then 1, etc to see the transition each time.
Hitting 0 multiple times should block the game though; can you see the wait cursor when you hit a key that supposedly does nothing?

Sorry didnt see that question.... let me check that...




.... Just checked, and Yes i see the wait cursor during the time that i cant do a thing :(
« Last Edit: 07 Nov 2017, 20:14 by henrikes »

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Transition from a Background to another
« Reply #6 on: 07 Nov 2017, 21:01 »
Right; so the keypress does register, and the loop runs, but the screen doesn't change.

The first thing I'd try is adding newBackground.Release(); to the end of the function.

If that doesn't work, try using
Code: Adventure Game Studio
  1.   // before loop
  2.   DynamicSprite* sprite = DynamicSprite.CreateFromBackground(1 + bBlur);
  3.  
  4.     // inside loop
  5.     mainBackground.drawImage(0, 0, sprite.Graphic, i);
(i.e. drawing a sprite to the current background's surface, as opposed to drawing a surface)

Re: Transition from a Background to another
« Reply #7 on: 07 Nov 2017, 21:30 »
Tried both and the result is still the same.

increased the decrement of the i variable and works much better...
Code: Adventure Game Studio
  1.    
  2.   while ( i > 0 ) {
  3.     mainBackground = Room.GetDrawingSurfaceForBackground();
  4.     mainBackground.DrawSurface(newBackground, i);
  5.     //i --;
  6.     i = i-5;
  7.     Wait(1);
  8.     mainBackground.Release();
  9.    
  10.     Label1.Text = String.Format("percent :%d", i);
  11.   }
  12.  

Khris Tried both your options and the result was the same :(

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Transition from a Background to another
« Reply #8 on: 07 Nov 2017, 21:39 »
Frankly I am not sure if that's related to your problem, but I just wanted to say that you must call Release before screen gets updated, in your case that's before Wait(1), otherwise your changes to surface won't be shown in time. (In practice this depends on graphics driver game is run with, for software driver calling Release is not essential, but Direct3D requires it to be called)
« Last Edit: 07 Nov 2017, 21:45 by Crimson Wizard »

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Transition from a Background to another
« Reply #9 on: 07 Nov 2017, 22:41 »
I tried your code as-is, and it worked perfectly fine for me.
Where .Release() is called doesn't matter apparently, and the background would go blurry and clear multiple times just fine, whenever I pressed the respective button.

When you say "works much better", are you referring to the fact that it's faster? Or does it suddenly work with subsequent keypresses? Please try to be precise, we really want to help, but not stating clearly and exactly what is or isn't happening makes it quite tedious to help you.

Re: Transition from a Background to another
« Reply #10 on: 08 Nov 2017, 22:11 »
A video trying to show what i mean

Video test

You can see what i mean with after i do the transition it takes a long time before i can do it again....

Now a second video with the "i = i-5;", basically its faster

Video test 2
« Last Edit: 08 Nov 2017, 22:21 by henrikes »

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Transition from a Background to another
« Reply #11 on: 08 Nov 2017, 22:34 »
From these videos, I fail to see the problem. It seems to accept keypresses as soon as the transition is over. It's blocking while the transition is ongoing, but that's the way you've coded it, by putting the Wait(1) call inside the loop.

If you want it to be able to reverse the transition while it's still ongoing (or do other things while the transition is happening), you need to make it non-blocking, which basically means that instead of having the code in a loop, you put it in repeatedly_execute(), without the Wait().

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Transition from a Background to another
« Reply #12 on: 08 Nov 2017, 22:41 »
I have noticed that the image doesn't seem to change anymore during the last 30 or so frames. The reason is that the previously drawn semi-transparent pixels all add up to the actual color, thus the visual transition is complete long before i reaches 0.

Looks like this has been the issue the entire time? You thought the transition is finished but the game was still blocked and therefore didn't react to your keypress?

A quick fix is to increase the speed, a proper fix is to restore the previous background before drawing the next transparency step. That way the fade is perfectly linear from 100 to 0.

Re: Transition from a Background to another
« Reply #13 on: 09 Nov 2017, 19:42 »
Looks like this has been the issue the entire time? You thought the transition is finished but the game was still blocked and therefore didn't react to your keypress?

Yes it was :)

A quick fix is to increase the speed, a proper fix is to restore the previous background before drawing the next transparency step. That way the fade is perfectly linear from 100 to 0.

Just tried the "proper fix" (I think) and it looks way better video.

Thank you all for the help :)
Sorry for not beeing clear at start :)