[Suggestion] setSize in setDarawble method (Image class)
See original GitHub issueIssue 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:
- Created 6 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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 callpack
.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.