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 8226529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:48:05+00:00 2026-06-07T15:48:05+00:00

My Code: I’m currently developing a game and throughout several different parts of the

  • 0

My Code:

I’m currently developing a game and throughout several different parts of the code I’m using some resources (Images/Sounds/Animations etc.). To avoid loading the same resource twice I wrote a ResourceManager, that returns the wanted resource if I pass a string to it.

Here’s an example:

Image myImage = imageManager.getImage("princess");

This way I can reference a resource without knowing the name of the file or position of it, when I want to use it.
The trick here is that I have to load the images before I can get them like so:

imageManager.loadImage("res/princessImage.png", "princess");

This creates the ImageObject from the given file, and stores it into a HashMap with the given key.

My Problem:

I really don’t want to hardcode the paths to these resources, because I’d have to change the sourcecode every time I decide to move or rename any of the resource-files.

A possible solution (?):

I thought about creating another HashMap that reads some kind of configFile and maps the in-code-resource-names to the resource-paths in a HashMap. The file would look somewhat like this:

princess: res/princess.png
hero: res/hero.png
sword: res/items/sword.png

This way I could use resource-names like “princess”, “hero” or “sword” safely and don’t worry about their position on the hard drive while I’m coding. Whenever I move or rename a resource-file I just update the path/name in this configFile and everything would be fine.

On the other hand I think it’s pretty ugly to have one giant file that maps every in-code-resource-name to a path. This could result in one giant String to String HashMap which I’d have to store in the ResourceManager aswell. Things could get pretty confusing/unclear.

Does anyone have a better solution for me?

I’d really appreciate your help,

Thanks 🙂

  • 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-06-07T15:48:07+00:00Added an answer on June 7, 2026 at 3:48 pm

    Using a config or resource file as you described is a fine approach. Instead of populating a HashMap, though, consider using ResourceBundle or PropertyResourceBundle. It is designed to hold/access such things. http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code to create new form instance of a closed form using form name I
Code below sets default values for new row if row is added using form.
Code Currently my code looks like that. $stmt = $this->db->prepare(SELECT m.id, m.from_id, m.to_id, m.subject,
Code (Note that the result will not display properly without the images referenced) I'm
code: #include<iostream> using namespace std; template<class T, int N> class point { T coordinate[N];
Code: #include <iostream> using namespace std; #define ADD(x,y) ((x)+(y)) int main( int argc, char**
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
Code in html.haml in Rails using AngularJS %table %tbody{:ng-init => my_model=#{@current_user_things.to_json}} %tr{:ng-repeat => row
Code #include <iostream> using namespace std; int main() { const int N = 22;
code snippet: // some code SDL_Surface* t = Display->render_text(text); int z=100; Display->blit_image(t,z,100); // some

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.