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

  • Home
  • SEARCH
  • 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 7874851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:52:55+00:00 2026-06-03T02:52:55+00:00

In the pure Java version, calling width() or height() on Image or on ImageLayer

  • 0

In the pure Java version, calling width() or height() on Image or on ImageLayer works. But with HTML5 backend I get zero if I call it too early.

Image image = assets().getImage("images/myimage.png"); 
ImageLayer layer = graphics().createImageLayer(image);
float w1 = image.width(); 
float w2 = layer.width();

I tried right after the getImage() in the initialization code of the game and also from the paint() method, the first time paint() is called. But I always get zero with the HTML5 backend (Chrome, MacOs).
However, if I call width() after the second call to the paint() method I get the correct width.
So it seems that with the HTML5 backend the semantics is different: the width() method returns the correct width of an image / layer after it has been rendered a first time.

Is my interpretation correct and how to get the size before rendering?

  • 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-03T02:52:57+00:00Added an answer on June 3, 2026 at 2:52 am

    Have you tried using the AssetWatcher? It looks like those first width calls are outracing the document’s ability to load the image.

    Here’s a simple example of the AssetWatcher in action:

    • http://playn-2011.appspot.com/slides/index.html#37

    And here’s an implementation of AssetWatcher from the PlayN Showcase sample:

    • http://code.google.com/p/playn-samples/source/browse/showcase/core/src/main/java/playn/showcase/core/sprites/SpriteLoader.java?#99
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm tasked with converting an existing Java/C++ mixed web-application to pure Java, but I'm
Do pure java jdbc drivers (Type 4 ) call native database API functions such
Is there a pure-java way of setting the android:button attribute? My use case is
The Situation: I'm optimizing a pure-java implementation of the LZF compression algorithm, which involves
I'm building a video player in pure Java around JMF, with completely custom UI
I've used JAXB Marshaller as well as my own marshaller for marshalling pure java
I have 2 projects: Java EE - with Rest API Pure Java using Java
I have been searching for a pure Java SSH library to use for a
Hi I need to run netbeans as pure java or java with a .bat
How can I pass Parameters between JSP pages using pure Java Code? I.e. I

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.