Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Basic Array question c++ Sdl

Options
  • 05-01-2007 8:20pm
    #1
    Closed Accounts Posts: 311 ✭✭


    Hi my first function creates 900 particles and assigns them positions in x, y, and velocities in both as well
    it is called initparticles

    I then want to draw thos epositions onto the screen using a drawParticles function like this;
    void initParticles()
    {
    double pX[900];
    double pY[900];
    double vX[900];
    double vY[900];
    
    for (int i=1;i<900;i++)
    {
    pX[i]=dRand(300);
    pY[i]=dRand(300);
    vX[i]=1;
    vY[i]=1;
    }
    }
    
    void drawParticles(){
    for (int i=1;i<900;i++)
    {
    myCircle(pX[i],pY[i],10,0xff00ff);
    }}
    

    note the myCircle function works it produces a circle at the point x,y with radius 10 and the colour

    the dRand creates a random number between 1 and the max number i put into it 300 in this case.


    However my particles are constantly updating there position to new random ones, how do I get them to stay put?


Comments

  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Surly in the first function, the arrays are local to that and won't exist when it finishes?
    Maybe you should create the arrays in the main and then use the functions, instead of creating them in the functions.

    Also arrays start at 0, not 1 :)

    Anyways i doubt that will answer anything for you but just something i noticed.


  • Closed Accounts Posts: 311 ✭✭Passport


    yes your right I fixed them, thanks.

    my question remains however.


  • Registered Users Posts: 304 ✭✭PhantomBeaker


    So, you're drawing a number of circles with these functions. By the way, take note of what Webmonkey said about declaring the arrays outside of the function body, this will help you in the long term.

    How are you calling the functions? I.e. what's the program that calls those functions. Where do you call those functions? How do you call those functions? What do those functions do? Should you be calling them that way?

    Remember: functionsthat do your your initial setup should only be called once.

    Hope that helps,
    Aoife


Advertisement