|
-
October 22nd, 2007, 03:04 AM
#1
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!
-
October 22nd, 2007, 04:04 AM
#2
Re: I cant figure out why this isnt animating >=/
where are you creating your timer?
-
October 22nd, 2007, 04:07 AM
#3
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!
-
October 22nd, 2007, 04:09 AM
#4
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
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!
-
October 22nd, 2007, 04:16 AM
#5
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
-
October 22nd, 2007, 04:18 AM
#6
Re: I cant figure out why this isnt animating >=/
That is because of this line of code: 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
-
October 22nd, 2007, 04:31 AM
#7
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!
-
October 22nd, 2007, 04:32 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|