piotr409 Posted January 10, 2014 Share Posted January 10, 2014 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.ThanksSource 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 : Link to comment Share on other sites More sharing options...
rich Posted January 11, 2014 Share Posted January 11, 2014 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 More sharing options...
piotr409 Posted January 11, 2014 Author Share Posted January 11, 2014 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 More sharing options...
WaltDjr Posted January 16, 2014 Share Posted January 16, 2014 [uPDATE] Also is it possible to change opacity of circle? I want to get transparent circle color. The way I was able to do this was game.debug.renderCircle(circle, 'rgba(255,255,255, 0.5)'); Link to comment Share on other sites More sharing options...
dnassler Posted February 22, 2014 Share Posted February 22, 2014 But what use is the debug render in non-debug mode? Debug does not work unless you are in CANVAS mode. I'd like to know how to render a sprite, any sprite at all, with transparency control. Does anyone know how to do that? Link to comment Share on other sites More sharing options...
Heppell08 Posted February 22, 2014 Share Posted February 22, 2014 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 More sharing options...
Recommended Posts