Sign in to follow this  
DNGunpla

Drag and Scale Object

Recommended Posts

Hi, I am looking for a way to drag and scale my object in my game.

Right now this is my code:
 

Quote

test: function(){
        test1 = this.game.add.graphics(0, 0);
        test1.beginFill(0x000000);
        test1.lineStyle(2, 0x0000FF, 1);
        test1.drawRect(168, 70, 46, 46);
        test1.endFill();
    },

    dotplacer:function(){
        dot = this.game.add.sprite(214, 116, 'blackdot');
        dot.anchor.setTo(0.5);
        dot.scale.setTo(0.3);
        dot.inputEnabled = true;
        dot.input.enableDrag(false);
        dot.allowVerticalDrag = true;
        dot.allowHorizontalDrag = false;
        dot.input.setDragLock(true, true);

        dot2 = this.game.add.sprite(261, 116, 'blackdot');
        dot2.anchor.setTo(0.5);
        dot2.scale.setTo(0.3);

        dot3 = this.game.add.sprite(168, 70, 'blackdot');
        dot3.anchor.setTo(0.5);
        dot3.scale.setTo(0.3);
    }

dot being the corner of the rectangle I want to drag and scale my rectangle.

dot2 and dot3 being the area I want to drag and scale my rectangle to.

Is there a way to do it?

Scaling the rectangle.png

Share this post


Link to post
Share on other sites

@flow

Okay I tried out the code and it is exactly what I want for dragging and scaling the object.

So I want to add in vertical scaling and horizontal scaling from one side at any point only.

Also I want to make it such that if the object is drag to like half the grid, it will automatically scale and snap to the nearest grid line.

Anyway to do it?

Example:

 5aab622894be7_ScalingRectangle2.0.png.0f2cc34a8cf3f46b8964c99284a982e8.png

Share this post


Link to post
Share on other sites

Sounds like a bunch of individual solutions, so I guess you just have to try out some stuff, but I'd probably start by adding some children to the "main" sprite in each corner and maybe some larger one along the edges, all giving them a certain version of the click-drag-scale function (scale.set(x, constant), scale.set(constant, y) and the diagonal one scale.set(d)).

For snapping to the grid you can try something like x = Math.round(x/10)*10 which would give you values like 10, 20, ... 110, 120, ...

 

Share this post


Link to post
Share on other sites

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.