JohnyFreeze Posted September 1, 2016 Share Posted September 1, 2016 Hi, I need help.I am creating game in phaser.I have one main sprite in the middle and few balls rotating around it.And right now, I need to connect the moving objects with center object.Done.But the lines are always top.And game.world.bringToTop(main); doesnt work whole app: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload,render: render, create: create, update: update }); function preload() { game.load.image('main', 'assets/sprites/main3.png'); game.load.image('ball', 'assets/sprites/ball.png'); } var main; var ball1,ball2,ball3,ball4,ball5,ball6; var line; function create() { game.stage.backgroundColor = '#001255'; line = new Phaser.Line(); main = game.add.sprite(400, 300, 'main'); main.anchor.setTo(0.5, 0.5); ball1 = game.add.sprite(400, 300, 'ball'); ball1.anchor.setTo(0.5); ball1.pivot.x = 200;// distance regulation ball1.rotation += 45; ball2 = game.add.sprite(400, 300, 'ball'); ball2.anchor.setTo(0.5); ball2.pivot.x = 200;// distance regulation ball2.rotation += 90; ball3 = game.add.sprite(400, 300, 'ball'); ball3.anchor.setTo(0.5); ball3.pivot.x = 200;// distance regulation ball3.rotation += 135; ball4 = game.add.sprite(400, 300, 'ball'); ball4.anchor.setTo(0.5); ball4.pivot.x = 200;// distance regulation ball4.rotation += 180; ball5 = game.add.sprite(400, 300, 'ball'); ball5.anchor.setTo(0.5); ball5.pivot.x = 200;// distance regulation ball5.rotation += 225; ball6 = game.add.sprite(400, 300, 'ball'); ball6.anchor.setTo(0.5); ball6.pivot.x = 200;// distance regulation ball6.rotation += 270; console.log(game.world); } function update() { var speed = 0.01; var length = 200; var realAngle = ball1.angle + 180; var radians = realAngle * Math.PI / 180; var x = ball1.x + Math.cos(radians) * length; var y = ball1.y + Math.sin(radians) * length; line.setTo(main.x, main.y,x,y); game.world.bringToTop(main);// doesnt work game.world.bringToTop(ball1);// doesnt work ball1.rotation += speed; ball2.rotation += speed; ball3.rotation += speed; ball4.rotation += speed; ball5.rotation += speed; ball6.rotation += speed; } function render() { game.debug.geom(line,"#ffffff"); } Link to comment Share on other sites More sharing options...
samme Posted September 1, 2016 Share Posted September 1, 2016 Hi JohnyFreeze, the debug layer is always drawn on the very top. Instead of Phaser.Line + debug.geom, you can draw a line on Phaser.BitmapData or Phaser.Graphics. Here is a graphics object: http://codepen.io/anon/pen/RGwoYQ Link to comment Share on other sites More sharing options...
JohnyFreeze Posted September 1, 2016 Author Share Posted September 1, 2016 Thanks a lot, Samme.Really thanks Link to comment Share on other sites More sharing options...
Recommended Posts