Jump to content

sprite parent and child how to have different alpha ? jsfiddle inside


espace
 Share

Recommended Posts

hi,

I'm starting this :

https://jsfiddle.net/espace3d/qf1oc4dh/3/

and i don't know how to set the alpha of sprite1 and table independantly ?

The parent sprite1 modify the value of his child table and i would have different value for alpha...

Thanks for your help.

 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload,create: create, update: update, render: render });

var table
var sprite1

function preload() {
   game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png');
}


function create() { 
game.physics.startSystem(Phaser.Physics.ARCADE);

    sprite1=game.add.sprite(400, 300, 'circle');
    sprite1.anchor.x=.5
    sprite1.anchor.y=.5
    sprite1.alpha=.1

game.physics.enable(sprite1, Phaser.Physics.ARCADE);

table=[]
for (var j=0; j < 2 ;j++) {

    table[j] = game.add.sprite(0, 0, 'circle')
    table[j].width = 50
    table[j].height = 50
    table[j].x = -25
    table[j].y = -25 + j * 50
    table[j].alpha=1
    sprite1.addChild(table[j])
}
}

function update() {
    sprite1.body.velocity.y = 10
}

function render() {
}

 

Link to comment
Share on other sites

A child will always be affected by it's parent. Position, scale, alpha.... any transformation. It makes sense; if you write your name on a piece of paper, then move the paper away from you, your name will look smaller. Your name hasn't actually changed in size, but the parent (the piece of paper) naturally effects it's children (your name).

If you want 2 sprites to be 'together' but not be effected by each other, then create a new group and have that become the parent - http://phaser.io/docs/2.6.2/Phaser.Group.html

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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