HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.93k stars 427 forks source link

Suggestion: Make it possible to customize FlxButton graphics without extending the class #3136

Closed moxie-coder closed 1 month ago

moxie-coder commented 1 month ago

There is no way to customize the graphics of the button without extending the class due to having no functions for customization, so extending the class is really the only way to get around the default graphics. I was hoping that it would be possible to customize it without even having to extend the class.

Geokureli commented 1 month ago

You don't need to extend it, just call loadGraphic on it. example

Geokureli commented 1 month ago

didn't mean to close this, lmk if you're still having troubles. Also, how are you customizing these by extension, if not with loadGraphic?

moxie-coder commented 1 month ago

didn't mean to close this, lmk if you're still having troubles. Also, how are you customizing these by extension, if not with loadGraphic?

okay firstly, my bad since I forgot Paths.image which means I didn't really have to extend it, but another issue arises when trying to replace it image

here's an snippet of the code I'm using too

            button = new FlxButton(0, 0, buttonName, function(){
                switch(buttonName){
                    case 'Story mode':
                        MusicBeatState.switchState(new StoryMenuState());
                    case 'Freeplay':
                        MusicBeatState.switchState(new FreeplayState());
                    case 'Credits':
                        MusicBeatState.switchState(new CreditsState());
                    case 'Options':
                        LoadingState.loadAndSwitchState(new options.OptionsState());
                    default: null;
                }
            });
            button.loadGraphic(Paths.image('mcButton/button_medium'), true, 200, 20);
            button.animation.add('idle', [0], 24, false);
            button.animation.add('hover', [2, 1], 24, false);
            button.animation.play('idle', false);
            button.label.setFormat(Paths.font('minecraftia.ttf'), 8, FlxColor.YELLOW, "center");
            button.y += 150 + i * 100;
            button.screenCenter(X);
            add(button);

should we move this into a discussion?