DNGunpla Posted March 15, 2018 Share Posted March 15, 2018 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? Link to comment Share on other sites More sharing options...
flow Posted March 15, 2018 Share Posted March 15, 2018 I just answered you in your other thread. I guess this should get you going? Link to comment Share on other sites More sharing options...
DNGunpla Posted March 16, 2018 Author Share Posted March 16, 2018 Okay I saw it and I will try it out thanks Link to comment Share on other sites More sharing options...
DNGunpla Posted March 16, 2018 Author Share Posted March 16, 2018 @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: Link to comment Share on other sites More sharing options...
flow Posted March 16, 2018 Share Posted March 16, 2018 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, ... Link to comment Share on other sites More sharing options...
Recommended Posts