Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Stutter when setting canvas visibile first time

22 Dec 2013, 18:19

I have a canvas that I programmatically set visible and hidden based on events in my game. This canvas is constantly animating (it shakes back and forth continually) and has children that are also programmatically set visible and hidden based on other events. These children are base Controls which frequently change their Templates. The parent canvas always starts hidden.

The first time, and only the first time that this canvas is set to visible there is a very noticeable stutter. Is there a way to mitigate this? Can I mask whatever time-consuming operation Noesis doing on when it first becomes visible by having it perform that operation without actually drawing the canvas? I've tried hacky solutions like positioning the canvas offscreen for a frame but it seems that whenever I draw it on screen for the first time it always causes my game to stutter.
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: Stutter when setting canvas visibile first time

24 Dec 2013, 17:25

When a new element (and all its contents) is rendered for the first time, all the associated resources (meshes and textures) are generated. We still don't provide a way to perform this task in a background process.

One possible solution to hide the stutter effect could be to make the canvas visible with a low opacity level (0.01) the first frame, and the next frame start an animation that smoothly fades in the canvas.

This trick could be applied to children too.

Changing the template of controls dynamically will create and destroy memory continuously. I think it will be more efficient to have several controls with all the different templates applied and make visible the one that corresponds each time.
 
Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: Stutter when setting canvas visibile first time

24 Dec 2013, 18:52

Thanks for the reply - I'll try seeing if I can play with the the opacity to load it up front (I would do it now but I am a bit swamped with other things atm).

For the templates, what we are trying to do is draw a number but due to limitations with font formats we need to have the digits as vectors (we talked about this a little in this thread: http://www.noesisengine.com/community_f ... ?f=3&t=241). Right now we have 10 templates for the digits 0-9 and canvas elements in a horizontal stack. This number right now is set up to be five digits long though ideally we'd like that to not be bounded. If we have a canvas for each template, wouldn't we need a set of 10 for each digit, or 50 canvases? Total memory allocation isn't really a concern (it is a PC game) but it still seems a bit inefficient. Is there a better solution or is this the most efficient way to render a frequently changing number without a font?
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: Stutter when setting canvas visibile first time

27 Dec 2013, 22:38

I will recommend to have several controls, each one with its corresponding template and playing with the visibility to show the appropriate one, better than having a unique control and changing its template dynamically, destroying and creating memory, measuring and arranging, creating corresponding render resources... each time template is changed.

If you need to display a 5-digit number, you should have something like this:
<StackPanel Orientation="Horizontal">
  <Grid>
    <Control x:Name="digit_4_0" Template="{StaticResource Number0}"/>
    <Control x:Name="digit_4_1" Template="{StaticResource Number1}"/>
    <!-- ... -->
    <Control x:Name="digit_4_9" Template="{StaticResource Number9}"/>
  </Grid>
  <Grid>
    <Control x:Name="digit_3_0" Template="{StaticResource Number0}"/>
    <Control x:Name="digit_3_1" Template="{StaticResource Number1}"/>
    <!-- ... -->
    <Control x:Name="digit_3_9" Template="{StaticResource Number9}"/>
  </Grid>
  <!-- ... -->
  <Grid>
    <Control x:Name="digit_0_0" Template="{StaticResource Number0}"/>
    <Control x:Name="digit_0_1" Template="{StaticResource Number1}"/>
    <!-- ... -->
    <Control x:Name="digit_0_9" Template="{StaticResource Number9}"/>
  </Grid>
</StackPanel>

Who is online

Users browsing this forum: Baidu [Spider] and 12 guests