Re: Animated shapes in VB.NET problem PLEASE HELP!!
Quote:
Originally Posted by Kaneoku
hello, this is my first post on this site. I am doing a program in school and i'm having a little trouble with it. I'm supposed to be making a animated circle and make it expand and retract, then from the center of the circle, make it look hollow. I have the circle drawn and everything but i just can't get the circle to expand and retract.
Ps. i'm kind of new to posting on forums so it might not be detailed good.
Thanks for any help
you need to post some of your code and enclose it in [ vbcode] and [ /vbcode] tags so someone can help you with it
Re: Animated shapes in VB.NET problem PLEASE HELP!!
what are you using to make the circle? are you using a control or are you drawing it with something like g.drawcircle?
Re: Animated shapes in VB.NET problem PLEASE HELP!!
im using g.drawcircle. I cant post code because im at home.
Re: Animated shapes in VB.NET problem PLEASE HELP!!
here is some code:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnimate.Click
Me.tmrAnimate.Start()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Me.tmrAnimate.Stop()
End Sub
Private Sub tmrAnimate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnimate.Tick
Dim FormSurface As Graphics = Me.CreateGraphics
FormSurface.Clear(Me.BackColor)
Dim Width As Integer = Width + 10
Dim Height As Integer = Height + 10
Dim MaxX As Integer = (Me.Width \ 2) - (Width \ 2)
Dim MaxY As Integer = (Me.Height \ 2) - (Width \ 2)
Dim RedBrush As New SolidBrush(Color.Red)
FormSurface.FillEllipse(RedBrush, 150, 150, 40, 40)
End Sub
Re: Animated shapes in VB.NET problem PLEASE HELP!!
hint (since its a school assignment and all i won't post the solution :rolleyes:): the variables that keep track of the width and height, as well as maxx and maxy are local, and are reset every time the timer ticks. that and the fact that no variable arguments are used when drawing the circle on the form. What you get is a flashing circle.
Now to fix this, you need to do two things:
1. Add variables in your drawing method.
2. Figure out a better way to keep track of the width and height of the circle. Either make those variables static and initialize them in a different way, make the variables have a larger scope, or (i recommend this) make a circle object.
Also keep in mind that if you have more code in this program then posted here imy help won't be as accurate
also, i may have overlooked something, i don't know. i don't claim to be a master
hope this helps
Frame
Re: Animated shapes in VB.NET problem PLEASE HELP!!
ok thanks for replying, i finally got the circle to expand but i cant get it to retract now lol. Im not at school so i cant post the code now.
Re: Animated shapes in VB.NET problem PLEASE HELP!!
getting it to retract should be identical basically, except you need a minX and minY that the circle will get drawn to, and you would subtract from the size each time instead of adding..
my advice to you is that you create 2 subroutines called ExpandCircle and another called RetractCircle (i will let you guess what they should do :bigyello: )
and your form should have a variable specifying which one should be called on the timer tick event
so it looks something like this
VB Code:
Private Sub tmrAnimate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAnimate.Tick
if bExpandCircle then
ExpandCircle
else
RetractCircle
end if
end sub
in each of those subs should be logic to check to see if the circle has hit its max or min bounds, and if so reverse the boolean bExpandCircle so that on next timer tick, it does the other routine....
Re: Animated shapes in VB.NET problem PLEASE HELP!!
Quote:
Originally Posted by Kaneoku
ok thanks for replying, i finally got the circle to expand but i cant get it to retract now lol. Im not at school so i cant post the code now.
are you clearing the screen before redrawing?
gr.Clear(...)
Re: Animated shapes in VB.NET problem PLEASE HELP!!
yea i cleared before i drew. Ok so its the same thing but subtracting the size. I get it now thanks for all the help