Jump to content

Connecting Sprites


Anny
 Share

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

post-7914-0-01610000-1397101470.png

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

Hey!

 

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

 Share

  • Recently Browsing   0 members

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