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

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.