Sign in to follow this  
Hashasm

How to drag dynamically crated sprite

Recommended Posts

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);
....

....

....

}

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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

 

 

 

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.