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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Basic Array question c++ Sdl

  • 05-01-2007 7: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, Registered Users 2 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, Registered Users 2 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