all groups > dotnet academic > february 2004 >
You're in the

dotnet academic

group:

code for animation effects



code for animation effects dr. S.
2/27/2004 6:16:05 PM
dotnet academic: I could use some assistance in code writing, as I am trying to create a simple colored picturebox that moves back and forth, repetetively, (left to right and back again, etc.). Below is one of the closest I have come up with thus far

If P1.Left < 900 The
P1.Left = P1.Left +
End I
If P1.Left >= 900 The
P1.Left = P1.Left -
End I

Re: code for animation effects Peter van der Goes
3/1/2004 7:18:33 AM

[quoted text, click to view]
simple colored picturebox that moves back and forth, repetetively, (left to
right and back again, etc.). Below is one of the closest I have come up
with thus far.
[quoted text, click to view]
OK, this code moves the picturebox left or right 4 pixels depending on the
current value of P1.Left. If the value is >=900 the box moves left. That
means, for example, that if P1's Left property starts at 500, the box will
move will move to the right until Left >= 900, at which point we subtract 4
from left, reducing the value to < 900 immediately, thus causing the box to
move back to the right again. Result, the box appears to move left to right
properly the first time, then the box will appear to "stick" at the right
end of the range, never returning to the origin.
I'd recommend some sort of flag to indicate end of range or direction of
travel, rather than basing the decision on the value of the .Left property.

--
Peter [MVP Academic]

Re: code for animation effects dr. S.
3/1/2004 4:41:06 PM
Re: code for animation effects Peter van der Goes
3/2/2004 9:29:37 AM

[quoted text, click to view]
code be so that it returns left without starting another trip to the right?

Base the direction on the flag setting, not the current position.
(Disclaimer: this code has not been compiled or tested)
'Declare a flag as a form level variable so it's not initialized each time
you enter the code block
Public flag as boolean = false
Your move code is VB6-style, I suggest you check your help for the following
article:

Coordinate System Changes in Visual Basic .NET

'Your code should go something like this:
While flag = False

'code to move picturebox1 to the left

If PictureBox1.Location.X >= 200 Then

flag = True

End If

End While

While flag = True

'code to move picturebox1 to the right

If PictureBox1.Location.X <= 50 Then

flag = False

End If

End While


--
Peter [MVP Academic]

AddThis Social Bookmark Button