Jump to content

sprite display behind sprite ?


nExt
 Share

Recommended Posts

Hello i try display sprite in my game..

 

 

game.stage.backgroundColor = "1781A6";

var logo = game.add.sprite(screen.width/2, game_height/2,'logo');

..

next i set time 3s add and display cloud

this.timer = this.game.time.events.loop(Phaser.Timer.SECOND * 3, add_cloud, this);

.........

function add_cloud(){
    for(var i = 1; i<=5; i++){
        var cloud = this.game.add.sprite(screen.width * Math.random(),game_height,'cloud'+ game.rnd.integerInRange(1,3));
        cloud.body.gravity.y = - 30
    }
}

.

i want display cloud behind logo (as site : http://toastedware.com/) 

help me.. thank you !

Link to comment
Share on other sites

logo.bringToTop();

write it on function update, not create ???

 

if i want create group : stars = game.add.group();

and crete some star..  star= start.create(posX, posY, 'star');

 

can use function bringtoTop() to all star ???

 

thank you !

Link to comment
Share on other sites

Yes, this method should be called on update.

Yes, you can bring all the stars on top, but you can do this by bringing the whole group on top of the world.

game.world.bringOnTop(yourGroupHere);

The reason for this is that bringOnTop() brings the child to the top of the group. And as world is the group internally and every object is contained inside it, you can bring its children on the top.

Link to comment
Share on other sites

Yes, this method should be called on update.

Yes, you can bring all the stars on top, but you can do this by bringing the whole group on top of the world.

game.world.bringOnTop(yourGroupHere);

The reason for this is that bringOnTop() brings the child to the top of the group. And as world is the group internally and every object is contained inside it, you can bring its children on the top.

 

i try method bringOnTop() but i error ? (underfine method bringOnTop()) 

i try bringToTop() for cloud 

a.png

 

then the result is : (logo is ok)

ScreenShot2014-05-09at15.png

Link to comment
Share on other sites

and what is wrong?

 

PS: don't you consider upgrading to Phaser 2?

if change  game.world.bringToTop('clouds') to game.world.bringOnTop('clouds'); on function update()

 

in console (chrome) report : undefine is a not function (bringOnTop)

 

i learn and download phaser from 2 weeks ago in main site of phaser.. i don't know my phaser is Phaser 2 or not ..

 

i include only phaser.min.js in file index.html.. 

Link to comment
Share on other sites

  • 11 months later...
 Share

  • Recently Browsing   0 members

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