Results 1 to 10 of 10

Thread: C++ Help!

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts

    Unhappy C++ Help!

    Hiya, I'm trying to get some code to work...I am tryna get a shape to roll from left to right. So far i have written this code and my shape does go from left to right but does not roll. It is part of a GUI when i press the button it moves 2 to the right then stops. I find myslef having to press the button continously to make it roll. But what i want is to press the button once and make the shape roll from left to right and stop at position 300. Any suggestions on where im going wrong on my code? thanks

    //---------------------------------------------------------------------------
    void __fastcall TForm1::TimerTimer(TObject *Sender)
    {
    Timer->Enabled= false;
    int TotalShapeAmount;
    int ShapeAmount;
    TotalShapeAmount = 0;
    ShapeAmount = 2;
    if(Shape->Left<=300)
    {
    TotalShapeAmount = Shape->Left+ShapeAmount;
    Shape->Left=TotalShapeAmount;

    }
    }}
    //---------------------------------------------------------------------------

    void __fastcall TForm1::ButtonClick(TObject *Sender)
    {
    Timer->Enabled = true;
    }
    //---------------------------------------------------------------------------

  2. #2
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,168
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    Timer->Enabled= false;

    is stopping subsiquent requests to timer, without the button been clicked, I'm guessing you want that after the IF.
    throw new ArgumentException (String, String, Exception)

  3. #3
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,900
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    Yeah the problem is you're switching off the timer each time it moves the shape. Try putting the Timer->Enabled= false; as an else clause after the if.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    Oh right i see, I removed the Timer->Enabled = false; statement and it worked.
    In the inpsector in Borland Builder 5, I had enabled it to false; so really i was repeating myself.

    Thank you to every one who replied.
    Jas

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    ok now ive got another problem... My shape rolls, but ihave to get it move roll gradually to stop slowly.
    Using this code it rolls and then rolls FASTER to a stop. but i want it to roll and SLOWLY stop :S
    Any suggestion on this code!

    {

    int TotalShapeAmount;
    int ShapeAmount;
    TotalShapeAmount = 0;
    ShapeAmount = 6;
    Button->OnClick;
    if(Shape->Left<=550)
    {
    TotalShapeAmount = Shape->Left+ShapeAmount;
    Shape->Left=TotalShapeAmount;
    if (Shape->Left>350)
    {
    TotalShapeAmount = Shape->Left+(ShapeAmount*0.5);
    Shape->Left=TotalShapeAmount;
    }
    }
    }

  6. #6
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,900
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    You're adding to it twice if it's close to the end which makes it accelerate, you only want to add to it once.

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    How do u mean twice? by the two if statements? I cant think of anything else LOL

  8. #8
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,900
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    Code:
    TotalShapeAmount = Shape->Left+ShapeAmount;
    Shape->Left=TotalShapeAmount;
    if (Shape->Left>350)
    {
      TotalShapeAmount = Shape->Left+(ShapeAmount*0.5);
      Shape->Left=TotalShapeAmount;
    }
    This moves it twice if Shape->Left > 350, if you put the first two lines into an else it wouldn't.

  9. #9
    Senior Member
    Join Date
    Jan 2005
    Location
    Manchester
    Posts
    2,900
    Thanks
    67
    Thanked
    182 times in 136 posts
    • Butcher's system
      • Motherboard:
      • MSI Z97 Gaming 3
      • CPU:
      • i7-4790K
      • Memory:
      • 8 GB Corsair 1866 MHz
      • Storage:
      • 120GB SSD, 240GB SSD, 2TB HDD
      • Graphics card(s):
      • MSI GTX 970
      • PSU:
      • Antec 650W
      • Case:
      • Big Black Cube!
      • Operating System:
      • Windows 7
    Also you should use ShapeAmount/2 instead of ShapeAmount*0.5 since you're using ints.

  10. #10
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked
    0 times in 0 posts
    I'm trying but i seem to be making a worse mess of it :S

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •