Jump to content

Connecting Sprites


Recommended Posts

Hey guys!


I have asked about this in different topics but I haven't been able to find a good way to do it. What I need is to connect sprites dragging and dropping a point of one of them (like a button) to connect it to another sprite. I have tried to do this creating lines with a bitmap and using new Phaser.line but I don't want any diagonal line and when I use bitmap I haven't been able to create multiple lines. I thought of adding a sprite with the draw of the line but that wouldn't follow the player's movement ): I wan't it to be whatever the player draws on the field that connects the two sprites (but with straigth lines, like if they were cables that connect 2 electronic pieces)


I add an image to illustrate what i'm trying to do


Thank you so much in advance


PD: Ignore B's position haha


Link to comment
Share on other sites

So you  in effect want 3 lines: One from the origin to the middle, one from the middle to the cursor, and one to connect the two...?
Perhaps try a Graphics object?


psudeo code:

create function(){    create and store the graphics object.}update function(){    while button is down    {        clear graphics object;        //Draw from start to middle...        graphics draw line from {x:originX, y:originY} to {x: distance between origin and cursor/2 y:originY};        //Draw from middle to end...        graphics draw line from {x:distance between origin and cursor/2 y:cursorY} to {x: cursorX y:cursorY};        //Connect the two...        graphics draw line from {x:distance between origin and cursor/2 y:originY} to {x: distance between origin and cursor/2 y:cursorY};    }}
Link to comment
Share on other sites



I used your pseudocode and it works great, but what if I wanted to create more than one line and leave the previous one drawed in the bitmap? For example, I went from A to B and clicked in B so the line connected them and now I want to connect C and D. I need to use

this.line = game.add.bitmapData(800, 600);
        this.sprite = game.add.sprite(0,0,this.line);

for as many lines as I want?


Thank you for your time

Link to comment
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.

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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...