question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Suggestion] setSize in setDarawble method (Image class)

See original GitHub issue

Issue details

At the method setDrawable in the Image class, shouldn’t be there a setSize(getPrefWidth(), getPrefHeight()); like the constructor with drawable ?

I used the Image class where i changed the image at runtime. I called the Image() consturctor to create it and setDrawable to change the image. Because I used the constructor withoud a drawable, the size weren’t set and after using setDraweble there were no image drawn at the screen.

Version of LibGDX and/or relevant dependencies

gdx 1.9.7

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MobiDevelopcommented, Dec 13, 2017

You can call the pack() method to set size to preferred size and perform a layout, but if we want a setDrawable that also sizes, that should be a new method so as to not change existing behavior.

0reactions
NathanSweetcommented, Dec 18, 2017

setSize(getPrefWidth(), getPrefHeight()) is done in scene2d.ui widget constructors to give the actor a size at construction time for more convenient use with groups that do not layout their children. This is described in the pack javadocs, as well as why constructors shouldn’t call pack.

When a Drawable is set, I don’t think we ever want to change the Image size as a side effect. I understand it can be a gotcha when using the no-arg Image constructor (or a null drawable), then setting a drawable later AND using the image actor’s size rather than pref size, however any time you are using the actor’s size and not the pref size you need to take extra care to sizing the actor. If you want the actor size to be the pref size you need to call pack after anything that changes the pref size, such as setting a new drawable.

We can add javadocs for the no-arg Image constructor to make it a bit more discoverable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found