HaxeFlixel / HaxeFlixel/flixel-ui

FlxUIButton creates incrementally larger graphic keys

Open
#268 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
201
Forks
75
PR merge metrics
No merged PRs in 30d

Description

Within addIcon(), it sets the key to a new string using it's own string. Because it combines the strings, the string continually grows in length when refreshing the sprite.

public function addIcon(icon:FlxSprite, X:Int = 0, Y:Int = 0, ?center:Bool = true)
...
                // create a unique key for the new graphic
		var key = graphic.key + ",icon:" + icon.graphic.key;
		var newGraphic = FlxG.bitmap.add(newBmp, false, key);
...

This makes every addIcon call add a new image to the cache since the string is always different.

What's the best way to cache the graphic + icon without creating a new instance in the graphics cache? It needs to play nice with the removeIcon() code as well, which clears the graphic's bitmap.

If there's no easy way (or not necessary?), we could just set var newGraphic = FlxG.bitmap.add(newBmp); to avoid the growing string and allow the system to generate an incremental "pixels" + _lastUniqueKeyIndex key for the image.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in FlxUIButton.addIcon(), focusing on how the graphic key is composed and passed to FlxG.bitmap.add(). Read removeIcon() alongside it to understand bitmap clearing and cache ownership. Done means repeated sprite refreshes do not create ever-growing cache keys and remain compatible with removeIcon().

Written by the indexing model from the issue text.

Assessment

Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.