Anny Posted April 10, 2014 Share Posted April 10, 2014 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 More sharing options...
XekeDeath Posted April 10, 2014 Share Posted April 10, 2014 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 More sharing options...
Anny Posted April 12, 2014 Author Share Posted April 12, 2014 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 usethis.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 More sharing options...
Pedro Alpera Posted April 12, 2014 Share Posted April 12, 2014 I have made a rough example: http://pedroalpera.com/phaser/playground/connectingsprites_example/You can download the files attached to this post connectingsprites_example.zip Anny 1 Link to comment Share on other sites More sharing options...
Anny Posted April 14, 2014 Author Share Posted April 14, 2014 Wow, the example is great! I didn't know I could use an array, now I can have a function that creates lines in the arrangement . Thank you! gracias n.n Link to comment Share on other sites More sharing options...
Recommended Posts