Thread: animated drawing methods in c#

  1. #1
    budding software engineer luigi40's Avatar
    Join Date
    Jun 2004
    Location
    South Coast UK
    Posts
    61

    animated drawing methods in c#

    i am writing an application using .net ide which will animate a processor. Im new to C# language. Im sure this has been done before however after searching briefly on the net for help i cant find anything specific to my needs.

    Which is to have various different lines (width 10 pixels) on a form, at certain times i want to show a small block ( different colour, representing data) move along a certain line (bus). A lecturer at uni has suggested i do something like this

    Code:
    private int busLength = 25;
    private int[] busPath = {x,y,x,y,x,......};/*the x,y points of a certain bus*/
    private int dataPos; //position of data on bus
    private int oldDataPos;//previous position of data
    private int busWidth;
    
    Paint()
    {
         for(int 1=0;i<busLength;i++)
          {
            color.grey
            if(i==dataPos)
            color.red
            object.FillRectangle(anotherobject, busPath[i*2]-5,busPath[(i*2)+1]-5, color);
    }
    i tried playing around with using the array index as an arg in the FillRectangle method with no success (Array out of bounds exception)

    can some help me get off the ground or point me in the right direction please
    Last edited by luigi40; 01-29-2005 at 01:07 PM.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    First you should start writing code that compiles

    Try to draw a single rectangle with fixed values.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Hey luigi40! Are you painting onto a form?

  4. #4
    budding software engineer luigi40's Avatar
    Join Date
    Jun 2004
    Location
    South Coast UK
    Posts
    61
    please excuse my previous code as this was pasted after spending all day trying various ways to get the drawing to work, i have managed to animate a rectangle over a line (width 10) using a timer to call the OnPaint method, however the line doesnt draw properly, i.e. there are glitches, not sure if this is my monitor.

    i will practice some more today and post my compilable code

    Kleid, yes im drawing on a form, various lines 10 pixels wide, with animated rectangles moving along the lines.


    thanks in advance

  5. #5
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by luigi40
    ... have managed to animate a rectangle over a line (width 10) using a timer to call the OnPaint method, however the line doesnt draw properly.
    That is strange! Try something like this in the onPaint method:
    Code:
    private void onPaint( Iforgot sender, Iforgot e )
    {
       // Get graphics object from the system
       
       Graphics g = e.Graphics;
    
       // Draw the line using the graphics object
       
       g.drawLine( new Pen( Color.Black ), new Point( 10, 10 ), new Point( 20, 20 ) );
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  2. Turn Based Stradegy System Methods
    By TylerMoyer in forum Game Programming
    Replies: 2
    Last Post: 07-30-2007, 10:45 PM
  3. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03:09 PM
  4. Replies: 8
    Last Post: 07-27-2003, 01:52 PM
  5. drawing minimaps and radar screens.
    By Eber Kain in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 11:44 AM