views:

110

answers:

1

// Particle Stuct Instance private Sprite[] mParticles = new Sprite[10];

/// Particle emitter Properties
private Context mContext;

private int mPositionX, mPositionY, mWidth, mHeight, mNumParticles;


private Rect srcRect, dstRect;

/*** Constructor ! ***/
public ParticleEmitter(Context c, Sprite spriteImage, int num_particles) {

    super(c);
    mContext = c;

    Sprite[] Particles = new Sprite[10];

    Particles[0] = new Sprite(mContext, R.drawable.icon);

//  mParticles = spriteImage;
    //mParticles[num_particles].InitAttributes(c, R.drawable.icon);

    // Allocate Particles instances and copy into mParticle member
    //mParticles = new Sprite[num_particles];
 //   Sprite sprite1 =  new Sprite(mContext, R.drawable.icon);
//    Sprite sprite2 =  new Sprite(mContext, R.drawable.icon);

  //  mParticles[0] = spriteImage;
   // mParticles[1] =  sprite2;
/*  for(int i = 0; i < num_particles; i++)
    {
       mParticles[i].InitAttributes(mContext, R.drawable.icon);
       mParticles[i].setXPosition(i);
    }  */

//   mParticles[0].InitAttributes(mContext, R.drawable.icon);


    // nullify our positioning attributes
    mPositionX = mPositionY = 0;

}
A: 

When you say new Sprite[10] is creates an array of ten Sprite references, which are all equal to null by default. It does not create any new Sprite objects. After this, you'll likely want to create a new Sprite object to stick in each of these ten places. For example:

Sprite[] rgSprite = new Sprite[10];
for (int i = 0; i < rgSprite.length; i++) {
    rgSprite[i] = new Sprite(mContext, R.drawable.icon);
}
Gunslinger47
Thanks for the responses guys! Gunslingers you were indeed correct. However, I ended up using Java generics like List and ArrayList to manage my instances ( which worked brilliantly for my needs ). Example: // Particle Instance Array stucture using Generics <br> private List<Sprite> mParticles = new ArrayList<Sprite>(10);... Then I would just iterate through the list instantiating them with new. Thanks for the help.
Psypher