Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

AutoUi for GameMaker

A UI system for GameMaker for responsive, dynamic interfaces in seconds · By ome6a1717

Are images scalable?

A topic by fractal-odyssey-game created Jan 21, 2026 Views: 97 Replies: 6
Viewing posts 1 to 2

I'm trying to display sprites (as part of a container) at a smaller size than their actual (i.e. image_xscale = 0.5), but can't seem to find the corresponding setter functions for image. I can see that the xscale and yscale variables are included as privates, which implies to me this lack of scaling is intentional. Is there a reason for this, or am I just missing something?

Developer (1 edit)

I originally intended them to scale, but can't remember why I left it out.  I'll take a look, but in the meantime what I would do is place the image and set it's visibility to false.  Then you can just manually draw your

img = auto_image(<data>);
img.set_visible(false);
// NOTE: you might need to add space using container.add_space(sprite_get_height(sprite) * scale)) to push the other elements
// DRAW EVENT
draw_sprite_ext(sprite, frame, img.get_bbox_left(), img.get_bbox_top(), etc.)

I think my hesitating factor was whether or not scaled images should push the adjacent content...maybe I'll add this to the next update.

Is there any plan to further develop this? I've finally gotten around to implementing autoUI into my project, and the proposed solution only partially works. Specifically, it has issues with reducing the sprite size (your proposed solution works for increasing sprite sizes). I can work around this by add_space-ing a negative value, but a strange vertical offset occurs within a container_h (which itself is contained in a container_v). I'm trying to find a workaround currently, but haven't had much luck so far.

Developer

If you enable the set_scale code in the AutoUiImage script, does that do what you're asking for?  I've done some minimal testing and it does work that way, but I'm unsure specifically what issue you're running into.  You can also copy your code here and I can maybe help point you in the right direction.

(3 edits)

set_scale partially works, but seems to only scale the X dimension (while padding elements as if they were unscaled) for my container_h. These are vector images, if that matters.

I'll include my code, but as a warning it's very split up. I'll try and copy all the relevant snippets.
Both attempts (using a manual workaround and using set_scale) are included here. The only difference (aside from the two sections in the first block) is the last line of the first block, which calls uiContainerToElement instead of uiContainerImagesToElements when using set_scale.


        for (var i = 0; i < ds_list_size(_unit.actions); i++){
            var _action = ds_list_find_value(_unit.actions, i);
            var _sprite = _action.iconSprite;
            
            var _element = auto_image(_sprite);
            
            //SET_SCALE IMPLEMENTATION
            _element.set_scale(0.1);
             actionsSubContainer.add(_element);
            
            //MANUAL WORKAROUND IMPLEMENTATION
            /**           
            _element.set_visible(false);
            _element.staticScale = 0.1; //Easiest to toss a new field into the struct for reference later
            
            actionsSubContainer.add(_element);
            actionsSubContainer.add_space(-sprite_get_width(_sprite)*0.9);
            
            array_push(_actionImagesArray, _element);
            **/
        }
        
        actionsSubContainer.step(600*global.uiScale, (_yBase + 50) * global.uiScale);
        
        uiElements = array_concat(uiElements, uiContainerImagesToElements(actionsSubContainer, _actionImagesArray));


function uiContainerImagesToElements(_container, _images){
    
    var _array = [uiContainerToElement(_container)];
    
    for (var i = 0; i < array_length(_images); i++){
        var _subElement = createEmptyUIElement();
        var _imageElement = _images[i];
        
        _subElement.drawFunction = method({_imageElement}, function(_element){
            draw_sprite_ext(_imageElement.get_sprite(), 0, _imageElement.get_bbox_left(), _imageElement.get_bbox_right(), _imageElement.staticScale, _imageElement.staticScale, 0, c_white, 1);
        });
        array_push(_array, _subElement);
    }
    
    return _array;
}


function uiContainerToElement(_container){
    var _element = createEmptyUIElement();
    
    _element.drawFunction = method({_container}, function(_element){
        _container.draw();
    });
    
    return _element;
}


    if (true) {
        for (var i = 0; i < array_length(uiElements); i++){
            uiArray[i].drawFunction(uiElements[i]);
        }
    }

Correction - set_scale works for the y axis as well. I left out the second scale argument, and forgot that GML doesn't throw syntax errors for that sort of thing. Once this was fixed, the padding behaved as expected. Seems to be good for now!

Developer

Perfect!  I'll have to see if I can find a reason I commented that out and maybe undo that in the next update :)


Thanks!