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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:53:46+00:00 2026-06-01T14:53:46+00:00

I wrote a simple example that I expected would do it. The relevant code

  • 0

I wrote a simple example that I expected would do it. The relevant code is pasted below, complete source available here.

First, the method of my game class that draws three circles as canvas images using the asCanvasImage method on my Circle class:

public void drawThreeTransparentCircles() {
    // create an immediate layer and add to root layer
    ImmediateLayer circleLayer = graphics().createImmediateLayer(
            new ImmediateLayer.Renderer() {
                public void render(Surface surf) {
                    Circle redCircle = new Circle(-25, 0, 50, Color.rgb(
                            255, 0, 0), 0.5f);
                    Circle whiteCircle = new Circle(0, 0, 50, Color.rgb(
                            255, 255, 255), 0.5f);
                    Circle blueCircle = new Circle(25, 0, 50, Color.rgb(0,
                            0, 255), 0.5f);
                    surf.drawImage(redCircle.asCanvasImage(),
                            redCircle.getScreenX(), redCircle.getScreenY());
                    surf.drawImage(whiteCircle.asCanvasImage(),
                            whiteCircle.getScreenX(),
                            whiteCircle.getScreenY());
                    surf.drawImage(blueCircle.asCanvasImage(),
                            blueCircle.getScreenX(),
                            blueCircle.getScreenY());
                }
            });

    rootLayer.add(circleLayer);
}

And then asCanvasImage method of my Circle class:

public CanvasImage asCanvasImage() {
    int diameter = radius * 2;
    CanvasImage circleImage = graphics().createImage(diameter, diameter);
    Canvas canvas = circleImage.canvas();
    canvas.setFillColor(color);
    canvas.fillCircle((float) radius, (float) radius, (float) radius);
    canvas.setAlpha(alpha);
    return circleImage;
}

The alpha value is set to 0.5 for each circle. But this is the result when I run the Java version:

enter image description here

Edit: I discovered that if I change the alpha value on the rootLayer, it makes the images transparent:

rootLayer.setAlpha(0.5f);

However I wish to make each of the circle images independently transparent with different alpha values. Does that mean I have to add each image to its own layer and set the transparency on that layer?

  • 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-01T14:53:47+00:00Added an answer on June 1, 2026 at 2:53 pm

    I was able to create independent transparent circles using images layers. Is this the best way to accomplish this?

    I added an asImageLayer method to my Circle class that creates a circle image using the asCanvasImage method above then creates an image layer from that and successfully applies the alpha value:

    public ImageLayer asImageLayer() {
        CanvasImage image = asCanvasImage();
        ImageLayer imageLayer = graphics().createImageLayer(image);
        imageLayer.setAlpha(alpha);
        imageLayer.transform().translate(getScreenX(), getScreenY());
        return imageLayer;
    }
    

    My game class method that calls asImageLayer which in turn gets called by the paint method:

    public void drawTransparentImageLayers() {
        GroupLayer groupLayer = graphics().createGroupLayer();
        groupLayer.add(bgLayer);
        groupLayer.add(redCircle.asImageLayer());
        groupLayer.add(whiteCircle.asImageLayer());
        groupLayer.add(blueCircle.asImageLayer());
        rootLayer.add(groupLayer);
    }
    

    The result (the circles moves slightly at random leaving a trace):

    enter image description here

    It works but the movement appears to slow down over time. Performance issue?

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

Sidebar

Related Questions

I wrote a simple example, which estimates average time of calling virtual function, using
I am trying to understand type members in Scala. I wrote a simple example
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I wrote a simple UDP Server with Netty that simply prints out in logs
I wrote this simple class that provides buffering for general output operation: template <typename
I wrote the code below, but at runtime, when I press keys, the program
As a simple example, I want to write a CLI script which can print
how can i write dynamic javascript any simple example or any references. thanking you
I wrote simple load testing tool for testing performance of Java modules. One problem
I wrote a simple batch file as a PowerShell script, and I am getting

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.