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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:10:37+00:00 2026-06-15T15:10:37+00:00

according to examples from site andengine examples I’ve created own project but with more

  • 0

according to examples from site andengine examples I’ve created own project but with more than one object. Let’s say it is a chess board, I have 8 colors per 8 rectangles. Now I stuck because if one of rectangles with specific color will be set to false (I have variable isclicked = false/true) all rectangles with the same color will also also changed.
How should I fix this problem?

I wrote the same code like the source from link above. I store colors in single pic which is further splitting.

Here are a pics:
bar1
not clicked colors

bar2
clicked colors

notclicked
in game (none was clicked)

clicked
in game (one was clicked)

Here is my code, I’ll appreciate for any help.

public class Main extends SimpleBaseGameActivity {

    private static final int SIZE = 50;
    private static final int IMAGES_COUNT = 8;
    private static int CAMERA_WIDTH = 400;
    private static int CAMERA_HEIGHT = 600;
    private ITextureRegion[] mColorsRegion = new ITextureRegion[8];

    //
    private BitmapTextureAtlas mColorsTextureAtlas;
    private TiledTextureRegion mColorsTextureRegion;
    private TextureRegion mBackgroundTextureRegion;
    private BitmapTextureAtlas mBackgroundTextureAtlas;
    private BitmapTextureAtlas mPanelTextureAtlas;
    private TextureRegion mPanelTextureRegion;

    @Override
    public EngineOptions onCreateEngineOptions() {
        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    }

    @Override
    protected void onCreateResources() {

        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

        // stuff with colors
        this.mColorsTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 320, 40, TextureOptions.BILINEAR);
        this.mColorsTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mColorsTextureAtlas, this, "bar.png",
                0, 0, 8, 1);
        this.mColorsTextureAtlas.load();

        // woohoo! stuff with background
        this.mBackgroundTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 400, 800, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mBackgroundTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBackgroundTextureAtlas, this,
                "bg.jpg", 0, 0);
        this.mBackgroundTextureAtlas.load();

        // stuff with panel
        this.mPanelTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 400, 800, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mPanelTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mPanelTextureAtlas, this, "panel.png", 0, 0);
        this.mPanelTextureAtlas.load();

    }

    @Override
    protected Scene onCreateScene() {

        this.mEngine.registerUpdateHandler(new FPSLogger());

        final Scene scene = new Scene();
        scene.setBackground(new Background(5.F, 5.F, 5.F));

        // show background
        Sprite background = new Sprite(0, 0, mBackgroundTextureRegion, getVertexBufferObjectManager());
        scene.attachChild(background);

        // show panel
        Sprite panel = new Sprite(0, 400, mPanelTextureRegion, getVertexBufferObjectManager());
        scene.attachChild(panel);

        // show minirectangles

        // Init generating color numbers
        MyColors colors = new MyColors(IMAGES_COUNT);

        // Init minirectangles with randomed images
        MiniRectangle[] minirectangle = new MiniRectangle[IMAGES_COUNT * IMAGES_COUNT];
        for (int i = 0; i < IMAGES_COUNT; i++) {
            for (int j = 0; j < IMAGES_COUNT; j++) {
                final int index = i * IMAGES_COUNT + j;
                minirectangle[index] = new MiniRectangle(j * SIZE + 2, i * SIZE + 2, SIZE - 4, SIZE - 4,
                        mColorsTextureRegion.getTextureRegion(colors.getRan(index)), getVertexBufferObjectManager()) {

                    @Override
                    public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {

                        if (this.isVisible()) {
                            setClicked();

                            togglex(this.isClicked());

                        }
                        return true;
                    }
                };

                // further setting for minirectangle
                minirectangle[index].setIndexX(j);
                minirectangle[index].setIndexY(i);
                minirectangle[index].setNumber(index);
                minirectangle[index].setClicked(false);
                minirectangle[index].setColorNumber(colors.getRan(index));
                minirectangle[index].addColors(mColorsRegion);

                // attach to scene and register touch arena
                scene.attachChild(minirectangle[index]);
                scene.registerTouchArea(minirectangle[index]);
            }
        }

        return scene;
    }

    protected void togglex(boolean clicked) {
        this.mColorsTextureAtlas.clearTextureAtlasSources();
        boolean xclicked = clicked;
        BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mColorsTextureAtlas, this, xclicked ? "bar2.png"
                : "bar.png", 0, 0, 8, 1);

    }
}
  • 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-15T15:10:38+00:00Added an answer on June 15, 2026 at 3:10 pm

    You can’t change the contents of the texture atlas – all of your texture regions are referencing it, so they are all changed.

    Think of a texture atlas as a large array. The texture regions are like pointers to different regions in this array. So if you want to update your sprite’s texture region, you should point it to another area in the texure. But instead, you are changing the contents of this large array, the texture. So all of the texture regions which reference it are changing, too.

    Solution:

    You should load both images to your atlas, and change the texture regions only.

    Loading both images:

    this.mColorsTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 320, 80, TextureOptions.BILINEAR); //Note that I doubled the height of the texture.
    this.mColorsNotClickedTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mColorsTextureAtlas, this, "bar.png", 0, 0, 8, 1);
    this.mColorsClickedTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mColorsTextureAtlas, this, "bar2.png", 0, 40, 8, 1); //The position of bar2.png is not 0,0 because it'll override bar.png. If the height is 40, we position it 40 units below the position of bar.png.
    this.mColorsTextureAtlas.load();
    

    Now, when a rectangle is clicked, change it’s texture region.

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

Sidebar

Related Questions

I have created a basic site using ASP.NET routing according to Mike Ormond's example
I am analyzing a problem from an old asp.net site made by one of
According to this site: http://iosdevelopertips.com/cocoa/date-formatter-examples.html there is a class that handles formatting, which takes
According to the site, http://www.dba-oracle.com/t_nls_lang.htm Problem might occur even if both the database and
I've seen code examples (from the book Beginning iPhone 4 Development) where they both
I am trying to call a javascript function from php. According to all of
I have just started learning ruby reading from different resources. One of them is
According to maven site , and some tutorials on the web, mvn archetype:generate would
According to this site: http://httpd.apache.org/docs/2.2/howto/access.html I need to use something like the script below
According to this site http://www.searchable-pdf.com/content.php?lang=en&c=61 , a PDF can be searchable when a text

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.