espace Posted September 22, 2016 Share Posted September 22, 2016 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 More sharing options...
espace Posted September 22, 2016 Author Share Posted September 22, 2016 an another question i don't understand the rule to fix a child compared to this parent. it seems that the child must be 4x bigger than the parent to be at the same cut ....why ? https://jsfiddle.net/espace3d/ma4xh6pf/ Link to comment Share on other sites More sharing options...
trojanfoe Posted September 22, 2016 Share Posted September 22, 2016 I am noob when it comes to HTML5 game dev, however isn't it correct that the parent's alpha will effect the child's alpha, in much the same way the parent-child relationship effects most of the attributes? I got a clue from here (page 123). Link to comment Share on other sites More sharing options...
themoonrat Posted September 22, 2016 Share Posted September 22, 2016 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 More sharing options...
espace Posted September 22, 2016 Author Share Posted September 22, 2016 thanks trojanfoe, but if i understand good i can't have a parent with alpha =.1 and a children with alpha =1 my solution so is to use an image with the correct alpha pre-established. Link to comment Share on other sites More sharing options...
trojanfoe Posted September 22, 2016 Share Posted September 22, 2016 Or you could use a Group, as suggested by @themoonrat. Link to comment Share on other sites More sharing options...
espace Posted September 22, 2016 Author Share Posted September 22, 2016 Yes thanks @themoonrat but in my case i must apply à physics effect and it's not possible with group. So i use child and parent. Link to comment Share on other sites More sharing options...
Recommended Posts