Jump to content

Lines allways on Top


JohnyFreeze
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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