Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:40:39+00:00 2026-05-25T11:40:39+00:00

I have a GameLoop class with a ParticleSystem object defined in it. The ParticleSystem

  • 0

I have a GameLoop class with a ParticleSystem object defined in it.

The ParticleSystem contains an array of Particle objects – I don’t want to have to load an image for each individual particle, id like to just be able to draw from a source image in the GameLoop class – how can I do this in an efficient manner?

SOLUTION:

Here is what Dan S helped me come up with:

public class ResourceManager  {

Context mContext;   

public final HashMap<String, Bitmap> Texture = new HashMap<String, Bitmap>();

//Constructor
public ResourceManager(Context context)
{       
    mContext = context;
    Texture.put("particle1", loadBitmap(R.drawable.particle1));
}

public Bitmap getBitmap(String key)
{   
return Texture.get(key);
}

 /** Load an image */
    protected Bitmap loadBitmap(int id) { return   BitmapFactory.decodeResource(mContext.getResources(), id); }

  } //End ResourceManager

then define it in a class:

rm = new ResourceManager(mContext);

And then pass the rm variable down the way:

    ParticleSystem.Draw(rm, canvas);
   {
     Particle.Draw(rm, canvas);
    }

and in Particle class, there is a String assetKey I set in constructor – so that I can refer to the Bitmap by a name:

public void doDraw(ResourceManager rm, Canvas canvas) {
    canvas.drawBitmap(rm.getBitmap(AssetKey), xpos, ypos, null);
}

I hope this is helpful to someone else also.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:40:39+00:00Added an answer on May 25, 2026 at 11:40 am

    In your constructor of GameLoop create your bitmaps and hold a reference to them there, set them as final variables for added protection against accidental assignment. Whenever you create a new particle system pass them to the constructor or set them in an appropriate setter method.

    Example:

    // in GameLoop definition
    
    private Bitmap particleA;
    private Bitmap particleB;
    
    // somewhere in GameLoop constructor
    particleA = BitmapFactor.decodeResource (activity.getResources(), R.drawable.particle_a);
    particleB = BitmapFactor.decodeResource (activity.getResources(), R.drawable.particle_b);
    
    // where you build your particle
    Particle (GameLoop gl, ...) {
       oneLevelDown = new OneLevelDown(GameLoop gl, ...);
    }
    
    OneLevelDown (GameLoop gl, ...) {
       twoLevelDown = new TwoLevelDown(GameLoop gl, ...);
    }
    
    TwoLevelDown (GameLoop gl, ...) {
       particleABitmap = gl.getParticleA(); // simple getter
       particleBBitmap = gl.getParticleB(); // simple getter
    }
    

    Just keep passing GameLoop down until you’re done. This might not feel efficient but once you get the hang of it you’ll like, also see this article about Dependency Injection.

    Java memory usage example:

    class Car{
       public int year;
       public int name;
    }
    
    // Object variables are references to an object's data.
    
    Car a = new Car(); // first car object and variable. 
    a.year = 1990;
    a.name = "Sam";
    
    Car b = new Car();// second car object and variable
    b.year = 2000;
    b.name = "Bob";
    
    Car c = a; // third car **variable** but same car object as **a**
    
    // primitives are different
    
    int a = 23; // first variable, 4 bytes used
    int b = 45; // second variable, 4 bytes used (and a total of 8)
    int c = a;  // third variable, 4 bytes used (and a total of 12). c took on the value of a, but does not point to the same memory as a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working in J2ME, I have my gameloop doing the following: public void run()
I have tried to cast an implementation of my UIView class to my view
I want to draw a PARTIALLY transparent image on top of another (Making shadows
I'm building a game, and for my players I have a player class. This
In my game I have platforms similar to Doodle Jump. They each have their
I have a simple timer class in a game, intended to allow me to
I am making a game and have started to work on a class called
How would I remove any object from my array notafications where I.active = false
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.