Jump to content

Fix position after scale


gtspina
 Share

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]);
    }
});

 

Link to comment
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?

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

this should be fixed in the latest dev branch (-> 5.1 to be released within a few days), here an link to the latest build :

https://melonjs-builds.s3.amazonaws.com/index.html?prefix=artifacts/master/2120/build/

make sure to also update the debugPanel to the latest version if you want to give it a try before the release :

https://github.com/melonjs/melonJS/tree/master/plugins/debug

Link to comment
Share on other sites

  • 1 year later...

i thinks this is still not fixed

var scale =
{
   mul : 1,
}

this.TweenScale = new me.Tween(scale).to({mul:1.01}, 500).
onUpdate(()=>{
   this.scale(scale.mul, scale.mul);
});

this.TweenScale.easing(me.Tween.Easing.Quadratic.Out);
this.TweenScale.start();

here is the result, see the big purple circle, when scaling its position changed
997674453_bugscale.gif.ffb4949bb9428da0c3d1be6eddbd7dcb.gif

Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...