Click here to Skip to main content
15,909,539 members
Home / Discussions / C#
   

C#

 
GeneralRe: Something SImple Pin
MasterSharp9-Nov-07 12:21
MasterSharp9-Nov-07 12:21 
GeneralRe: Something SImple Pin
Malcolm Smart9-Nov-07 12:30
Malcolm Smart9-Nov-07 12:30 
GeneralRe: Something SImple Pin
MasterSharp9-Nov-07 12:39
MasterSharp9-Nov-07 12:39 
GeneralRe: Something SImple Pin
Malcolm Smart9-Nov-07 12:45
Malcolm Smart9-Nov-07 12:45 
GeneralRe: Something SImple Pin
MasterSharp9-Nov-07 12:51
MasterSharp9-Nov-07 12:51 
GeneralRe: Something SImple Pin
MasterSharp9-Nov-07 12:54
MasterSharp9-Nov-07 12:54 
GeneralRe: Something SImple Pin
Judah Gabriel Himango10-Nov-07 16:37
sponsorJudah Gabriel Himango10-Nov-07 16:37 
AnswerRe: Something Simple Pin
Matthew Butler9-Nov-07 13:30
Matthew Butler9-Nov-07 13:30 
Try this...
(I've just written this without testing it so there may be bugs)

Timer myTimer = new Timer();
bool goingUp = true;
int bottom = 0;	// The vertical position (in pixels) of the 'floor'
int distance = 0;	// The distance (vertically) the box jumps
 
// OnFormLoad put:    myTimer.Tick += new EventHandler(myTimerTick);
 
public void myTimerTick(object sender, EventArgs e)
{
    if (goingUp)
    {
        // Move box upward (1 pixel per 'tick')
        // And check to see if hit 'top'
        myPictureBox.Top--;
        if (myPictureBox.Top + myPictureBox.Height < bottom - distance) goingUp = false;
    }
    else
    {
        // Move box downward (1 pixel per 'tick')
        // And check to see if hit 'bottom'
        myPictureBox.Top++;
        if (myPictureBox.Top + myPictureBox.Height > bottom) myTimer.Stop();
    }
}
 
public void StartJump(int bot, int dist)
{
    bottom = bot;
    distance = dist;
    goingUp = true;
    myTimer.Interval = 50;	// myTimerTick called every 50ms
    myTimer.Start();
}

I hope this helps.

You then just need to call StartJump whenever needed.


Matthew Butler

GeneralRe: Something Simple Pin
MasterSharp9-Nov-07 14:04
MasterSharp9-Nov-07 14:04 
GeneralRe: Something Simple Pin
Malcolm Smart9-Nov-07 14:36
Malcolm Smart9-Nov-07 14:36 
GeneralRe: Something Simple Pin
MasterSharp9-Nov-07 14:49
MasterSharp9-Nov-07 14:49 
QuestionPublish / Download Pin
MasterSharp9-Nov-07 10:33
MasterSharp9-Nov-07 10:33 
AnswerRe: Publish / Download Pin
Judah Gabriel Himango9-Nov-07 10:43
sponsorJudah Gabriel Himango9-Nov-07 10:43 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 10:48
MasterSharp9-Nov-07 10:48 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 10:50
MasterSharp9-Nov-07 10:50 
GeneralRe: Publish / Download Pin
Judah Gabriel Himango9-Nov-07 10:54
sponsorJudah Gabriel Himango9-Nov-07 10:54 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 10:59
MasterSharp9-Nov-07 10:59 
GeneralRe: Publish / Download Pin
Judah Gabriel Himango9-Nov-07 11:03
sponsorJudah Gabriel Himango9-Nov-07 11:03 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 11:08
MasterSharp9-Nov-07 11:08 
GeneralRe: Publish / Download Pin
Judah Gabriel Himango9-Nov-07 11:21
sponsorJudah Gabriel Himango9-Nov-07 11:21 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 11:29
MasterSharp9-Nov-07 11:29 
GeneralRe: Publish / Download Pin
Judah Gabriel Himango9-Nov-07 12:05
sponsorJudah Gabriel Himango9-Nov-07 12:05 
GeneralRe: Publish / Download Pin
MasterSharp9-Nov-07 12:09
MasterSharp9-Nov-07 12:09 
GeneralRe: Publish / Download Pin
Judah Gabriel Himango10-Nov-07 16:36
sponsorJudah Gabriel Himango10-Nov-07 16:36 
Questionuser control an d combobox Pin
nhathoang9-Nov-07 9:43
nhathoang9-Nov-07 9:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.