Hashasm Posted February 13, 2017 Share Posted February 13, 2017 HI can some one suggest me how can i drag the sprite image which I am creating on click of HUD object. i am able to drag the sprites which i have created from the tiled map within object layer by registering them like me.pool.register("mainPlayer", game.playerdrag); But i am not able to drag the sprite even if i am registering in pool. have a look on my code onClick: function (event) { console.log("clicked!"); // me.collision.check(); camera = new me.Sprite(500, 500, { image: "building_64_64-02", framewidth: 134, frameheight: 134, }); me.pool.register("camera", game.playerdrag); me.game.world.addChild(camera, 10, game.playerdrag); .... .... .... } Quote Link to comment Share on other sites More sharing options...
Parasyte Posted February 13, 2017 Share Posted February 13, 2017 "Dragging" is something that has to be implemented on the entity/sprite/renderable class. You are creating a `me.Sprite` instance, which does not implement dragging or any pointer event handlers. You can use me.DraggableEntity instead, or subclass me.Sprite to support drag events. Quote Link to comment Share on other sites More sharing options...
Hashasm Posted February 14, 2017 Author Share Posted February 14, 2017 OK ..but still i have one doubt even if we use me.DraggableEntity how can i assign it to my sprite . for example game.square = me.DraggableEntity.extend. Here game.square is an object . onClick: function (event) { console.log("clicked!"); // me.collision.check(); camera = new me.Sprite(500, 500, { image: "building_64_64-02", framewidth: 134, frameheight: 134, }); me.pool.register("camera", game.playerdrag); me.game.world.addChild(camera, 10, game.playerdrag); .... .... .... } can i assign like this me.sprite=me.DraggableEntity.extend or any other syntax i have to use Quote Link to comment Share on other sites More sharing options...
obiot Posted February 14, 2017 Share Posted February 14, 2017 already discussed and covered here : i'm not sure why you open again a similar topic, and not rather comment on the previous one if you have further doubts ? as for the draggable object, as I was highlighting in the other thread, you can check the corresponding example here : http://melonjs.github.io/melonJS/examples/drag-and-drop/ , and its corresponding source code here : https://github.com/melonjs/melonJS/blob/master/examples/drag-and-drop/js/entities/entities.js Quote Link to comment Share on other sites More sharing options...
Hashasm Posted February 14, 2017 Author Share Posted February 14, 2017 hi @obiot you got me wrong ! i solved the drag and clone thing now after clone -drag-drop . while cloning i am creating a new sprite and droping it to my map. now i am trying to write drag and drop functionalities on it(newly created sprite). I think this explains that i am not asking the same topic thank you .. Now can someone help me on this. Quote Link to comment Share on other sites More sharing options...
obiot Posted February 14, 2017 Share Posted February 14, 2017 well ok, i guess i was confused by your request on how to clone and drag... anyway I put back my same answer with both way of achieving drag & drop, it's your time to play and experiment with it. Quote two possibilities : 1) using standard event (pointerMove, pointerDown, etc...) : see the shape example : http://melonjs.github.io/melonJS/examples/shapes/ and the corresponding source code here : https://github.com/melonjs/melonJS/blob/master/examples/shapes/js/entities/entities.js 2) using the drag event : see the drag example : http://melonjs.github.io/melonJS/examples/drag-and-drop/ and the corresponding source code here : https://github.com/melonjs/melonJS/blob/master/examples/drag-and-drop/js/entities/entities.js Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.