CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2007
    Posts
    375

    I cant figure out why this isnt animating >=/

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace _D_game_01
    {
        public partial class GForm : Form
        {
            Point BallLocation = new Point(10, 10);
            Size BallSize = new Size();
            Point LinePoint1 = new Point();
            Point LinePoint2 = new Point();
            int[] buffer = new int[1] { 0 };
    
            public GForm()
            {
                InitializeComponent();
            }
    
            private void GPanel_Paint(object sender, PaintEventArgs e)
            {
                Graphics G = e.Graphics;
    
                G.Clear(Color.CornflowerBlue);
    
                SetupLines(sender, e);
                SetupBall(sender, e);
    
                this.Invalidate();
            }
    
            private void SetupLines(object sender, PaintEventArgs e)
            {
                try
                {
                    e.Graphics.DrawLine(Pens.Black, LinePoint1 = new Point(0, e.ClipRectangle.Height / 6 * 5), LinePoint2 = new Point(e.ClipRectangle.Width, e.ClipRectangle.Height / 6 * 5));
                }
                catch { }
            }
    
            private void SetupBall(object sender, PaintEventArgs e)
            {
                try
                {
                    e.Graphics.DrawArc(Pens.Black, new Rectangle(BallLocation, BallSize = new Size(e.ClipRectangle.Height / 10, e.ClipRectangle.Height / 10)), 0, 360);
                }
                catch { }
            }
    
            private void Tmr_Update_Tick(object sender, EventArgs e)
            {
                try
                {
                    BallLocation.Y += buffer[0];
    
                    if (BallLocation.Y < LinePoint1.Y - BallSize.Height)
                        buffer[0] += 1;
    
                    if (BallLocation.Y >= LinePoint1.Y - BallSize.Height)
                        buffer[0] = 0;
    
                    if (BallLocation.Y > LinePoint1.Y - BallSize.Height)
                        BallLocation.Y = LinePoint1.Y - BallSize.Height;
                }
                catch { }
            }
    
            protected override void OnKeyPress(KeyPressEventArgs e)
            {
                if (e.KeyChar == (byte)Keys.Escape)
                    this.Close();
            }
        }
    }
    This is suposed to animate... I can't figure out why it doesnt. I've done this before. Why isnt it animating this time ^^
    ______________________________
    Thanks in advance!

    Dahwan
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  3. #3
    Join Date
    Mar 2007
    Posts
    375

    Re: I cant figure out why this isnt animating >=/

    I created the timer in the designer. It's enabled with an interval of 10.
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

  4. #4
    Join Date
    Mar 2007
    Posts
    375

    Re: I cant figure out why this isnt animating >=/

    Seems the timer isnt working at all =/
    If all my code in the timer tick is
    Code:
    this.Text += "a";
    The window title doesnt change at all.

    Whats wrong with the timer? =O
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

  5. #5
    Join Date
    Nov 2004
    Posts
    105

    Re: I cant figure out why this isnt animating >=/

    Hi

    Check, Whether time is enable or not,

    Check after loading the form or at the time of loading form

    Regards
    Ravi.Battula
    Ravi.Battula

  6. #6
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: I cant figure out why this isnt animating >=/

    That is because of this line of code:
    Code:
    this.Invalidate();
    in your paint handler. Please try to debug your program and see what happens. In addition I think you have some bugs in your timer function. Review the whole program.

    Laitinen

  7. #7
    Join Date
    Mar 2007
    Posts
    375

    Re: I cant figure out why this isnt animating >=/

    The bugs in the timer function doesnt matter It's not even started yet. I will keep that going after i've gotten the timer to work.
    I removed Invalidate(), but it still isnt moving
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

  8. #8
    Join Date
    Mar 2007
    Posts
    375

    Re: I cant figure out why this isnt animating >=/

    OK, i moved this.Invalidate() from the paint onverride to the Timer tick

    Working =D

    Thanks!
    Please vote the posts you find usefull.

    ---

    I'm back
    Bigger and badder
    Better and bolder
    Explaining stuff -
    With an improved vocabulary!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured