gtspina

Fix position after scale

Recommended Posts

Hi guys.

I'm trying to do a "zoom in" effect on a GUI_Object. But when scaling the image leaves the original collision field. How to keep the image centered with the collision field of the button?

 

Before click:

mg9vrV.png

After click:

5VJ3AW.png

Code:


game.UI.ButtonInit = me.GUI_Object.extend({
    init: function (x, y, image) {
        this._super(me.GUI_Object, "init", [x, y, { image: image, }]);

        this.anchorPoint.set(0, 0);
        this.floating = false;
    },

    onClick: function () {
        this._super(me.Sprite, "scale", [.8, .8]);
    },

    update: function () {
        return true;
    },

    draw: function (renderer) {
        this._super(me.GUI_Object, "draw", [renderer]);
    }
});

 

Share this post


Link to post
Share on other sites

If you are using the collision shapes for pointer events, you can create a plugin to patch me.input.globalToLocal() to apply the same scaling transformation. This won't make the debugPanel render the collision shapes scaled, but your plugin could also patch the debugPanel's draw method to apply the scaling transformation, if you needed to.

If, however, you aren't using pointer events, why would you want to scale the collision shapes at all?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.