1

I want to do the credits screen for a game, but the credits consists in a series of images. I could not find a container that allowed me to insert multiple images and scroll them, so I created a ListBox with buttons in it. These buttons have only an image and are not clickable, so they act like just images. As far as putting the images in a container that allows me to scroll it, is already covered. The problem comes when I want them to autoscroll, I found around the web a series of autoscrolling a ListBox but nothing seem to fit into what I want to do.

Here is what i have:

Global variables for this class

    GameTimer _timer = null;
    int _currentIdx = 0;
    int _elapsedTime;
    const int TIMER_DELAY_IN_MILLIS = 1000;

When the application navigates into this page:

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        _elapsedTime = 0;
        _timer = new GameTimer();
        _timer.UpdateInterval = TimeSpan.FromTicks(333333);
        _timer.Update += OnUpdate;
        _timer.Start();

        base.OnNavigatedTo(e);
    }

When the application updates:

    private void OnUpdate(object sender, GameTimerEventArgs e)
    {
        if (_elapsedTime > TIMER_DELAY_IN_MILLIS)
        {
            _elapsedTime -= TIMER_DELAY_IN_MILLIS;
            Credits.UpdateLayout();
            Credits.ScrollIntoView(Credits.Items[_currentIdx]);
            System.Diagnostics.Debug.WriteLine("" + _currentIdx + " Update: " + e.ElapsedTime);

            _currentIdx = ++_currentIdx % Credits.Items.Count;
        }
        _elapsedTime += e.ElapsedTime.Milliseconds;
    }

As you can see, I do something like an update for this class and based on that the listbox scrolls to the button (view) that is in the next index of the list, however the scrolling I am trying to get is a smoother and more movie-like. I do not know if I am using the right container or if there is something bad with my algorithm, any kind of help would be very appreciated [:

2 Answers2

0

Try using the ScrollToVerticalOffset method instead. This allows you to scroll with pixel-precision.

ColinE
  • 64,631
  • 12
  • 149
  • 215
  • I just tried that but when the listbox reaches the end I am unable to scroll it back up. Also, how to know when you reach the end of the listbox? – user1670054 Sep 14 '12 at 08:15
0

This article has some examples of how to animate scrolling in a ScrollViewer. Choose a good timespan for the length of your credits and animate the VerticalOffset to the end.

A-Type
  • 1,138
  • 7
  • 17