Thread: help with an animation

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    9

    help with an animation

    Hi, I am working on a small animation project in MFC. I have a line of code that looks like this : pictureBox1->Location=System:: Drawing::Point(x,y); I have x and y generating random number placing the picture box on the screen randomly. Basically I have a ball rolling around a square shaped pool table. I would like the ball (actually its a square pic of a ball) to disappear when it hits the corner where the pocket is but I dont know what syntax to use for that. The point I need the ball to vanish is at (-30,-32). I wanna say : If (pictureBox1.....==(-30,-32) then vanish, basically. Any suggestions would be great. If more info is needed let me know.
    Thanks!!

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Depends how MFC works, i have no idea of the function calls but i image you have some kind of Blit function? or is everything being drawn? anyway if it was to blit your images then i would just set:
    'if the ball coordinates are over the hole for the pocket then blit the pocket image.
    in other words refresh the 'empty pocket' image

    you could even use a sub animation that blits a couple of frames of 'ball disappearing into pocket' before the empty pocket image is finally shown again.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I don't know MFC, but seems like the same method I used in SDL would work. Set a boolean for the ball called sunk. Then wherever you draw the ball in your code encapsulate it in an if statement

    Code:
    if(!EightBall.sunk())  // if the current ball hasn't been sunk yet
    {
      EightBall.Render();  // draw the ball on the screen
    }
    that would work if the ball is a class. Also most squares are drawn by their corner coordinates, but in this case you might want to change it to draw around your centerpoint, so that you can do a collision check based off the centerpoint and the radius of the ball and not the size of the square. In your function to check if the ball is in the hole you just turn sunk to true(make sure you set the boolean to be default false), if the ball meets these conditions. When sunk is true the ball won't render itself.

    If you want a more direct answer applying to your code post a response with the attached code if its long or just post it in code tags if it's short.

    Hope that helps.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is not MFC. This is C++/CLI or C#. Which is it?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    I thought MFC was a C++ GUI Library for C++. So any C++ code would work in conjunction with it.

    The Windows GUI interface programming using Microsoft Foundation Classes (MFC) with Visual C++ and .Net hands-on approach tutorials

    so how would you differentiate by seeing C++ code that something wasn't MFC?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Lesshardtofind View Post
    I thought MFC was a C++ GUI Library for C++. So any C++ code would work in conjunction with it.

    The Windows GUI interface programming using Microsoft Foundation Classes (MFC) with Visual C++ and .Net hands-on approach tutorials

    so how would you differentiate by seeing C++ code that something wasn't MFC?
    You're right that MFC is a GUI library for C++. The reason that the OP's code looks like C++/CLI is the fact that it exactly matches the dot net API. See Point Structure (System.Drawing)
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Lesshardtofind View Post
    I thought MFC was a C++ GUI Library for C++. So any C++ code would work in conjunction with it.

    The Windows GUI interface programming using Microsoft Foundation Classes (MFC) with Visual C++ and .Net hands-on approach tutorials

    so how would you differentiate by seeing C++ code that something wasn't MFC?
    You are right. But then, one usually does not combine two different GUI libraries. Either you would use MFC, which is native, or you would use C++/CLI or C#, which are managed. They don't easily interop.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    Basically I am in a class titled "MFC Programming". I use C++ in Microsoft Visual Studio Pro writing code (c++) in windows form application. I attached a snippet of code from the program, It's everything getting the ball around the table.
    Thanks for all the input from everyone.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then you should be using a MFC Application and not a Windows Forms Application.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    did you try
    Code:
    if(x != -30 || y !-32) // as long as the ball doesn't equal -30, -32 ... the points you showed above
    { 	 
      pictureBox1->Location=System::Drawing::Point(x,y);  // draw the picture
    }
    of course you might want to change the fields from just a single point to greater or less than a certain x location and certain y. So you can define the size of the ball and if it can go into this field based on the size of the hole.
    Last edited by Lesshardtofind; 09-22-2010 at 01:35 PM.

  11. #11
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    Quote Originally Posted by Elysia View Post
    Then you should be using a MFC Application and not a Windows Forms Application.
    Well, thats what were suppose to do. Don't ask me I'm just the student

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then this cannot possibly be MFC, since it clearly is not.
    Misleading title. Tsk.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a boy come from china
    By luoyangke in forum General Discussions
    Replies: 117
    Last Post: 11-22-2009, 01:14 AM
  2. Threads in MFC
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 12-28-2005, 06:03 PM
  3. Animation class not working
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 03-02-2005, 06:48 AM
  4. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 05:37 AM
  5. 3D animation (difficult?)
    By maes in forum Game Programming
    Replies: 3
    Last Post: 09-08-2003, 10:44 PM