Jump to content

Circle opacity, render sprite


piotr409
 Share

Recommended Posts

Hey, I'm new to  forum and phaser.js.

[uPDATE]

I don't have anymore problem with my gravity, but I don't have idea how to show sprite on the circle, it renders circle on Jet.

Also is it possible to change opacity of circle? I want to get transparent circle color.

Thanks

Source Code : 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'Jet Fly', { preload: preload, create: create, update: update, render: render });function preload() {    game.load.image('arrow', 'img/jet.gif');}var circle;var sprite;var setGravityToPointXY = function(game,sprite,power, radiusLow,radiusHigh,pointX,pointY){    var pointXY = new Phaser.Point(pointX,pointY);    var tempDistance = Phaser.Point.distance(sprite,pointXY);   // console.log(tempDistance);    if(tempDistance>radiusLow&&tempDistance<radiusHigh){        var rotation = game.physics.angleToXY(sprite,pointX,pointY);        sprite.body.velocity.y += Math.round(Math.sin(rotation)*1000)/1000 * (power);        sprite.body.velocity.x += Math.round(Math.cos(rotation)*1000)/1000 * (power);    }};var getJetDegree = function(aX,aY){    return 90+180*(game.physics.angleToXY(new Phaser.Point(0,0),aX,aY)/Math.PI);};function create() {    game.stage.backgroundColor = '#0072bc';    sprite = game.add.sprite(50, 200, 'arrow');    sprite.anchor.setTo(0.5, 0.5);    sprite.angle = 90;    sprite.body.velocity.x = 50;    circle = new Phaser.Circle(400, 300,300);    circle.alpha = game.math.clamp(circle.lifespan / 1000, 0, 1);}function update() {   setGravityToPointXY(game,sprite,0.1,0,150,400,300);}function render() {    game.debug.renderCircle(circle,'#cfffff');} 

Screenshoot :

34ta5tz.jpg

Link to comment
Share on other sites

Your code works fine, what is happening is the sprite is going so slow it's going to sleep. This is something I'm experimenting with in the dev branch (which you're clearly using). Just add this for now:

    sprite.body.canSleep = false;

And it should behave as you expected (at least it does for me when I run your code with the above added)

Link to comment
Share on other sites

Your code works fine, what is happening is the sprite is going so slow it's going to sleep. This is something I'm experimenting with in the dev branch (which you're clearly using). Just add this for now:

    sprite.body.canSleep = false;

And it should behave as you expected (at least it does for me when I run your code with the above added)

 

Thanks.

All problems solved, topic to close.

Link to comment
Share on other sites

  • 1 month later...

Var dude;dude = game.add.sprite(X, Y, 'image');dude.alpha = 1;

Setting the alpha on the var given to the sprite will cause transparency. So if the alpha is 0 then there's no effect. Change it up from 0.0 to 1.0. 1 being totally invisible.

So if you wanted to change it on the fly ingame then use update coding and other variables to decide on the transparency all the way to invisible.

Hope this is kind of what you were looking for.

:)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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