AGoodUsername Posted March 10, 2016 Share Posted March 10, 2016 So I have a line that constantly rotates, and it is in a group: this.lines = game.add.group(); this.lines.enableBody = true; this.lines.physicsBodyType = Phaser.Physics.ARCADE; this.lines.createMultiple(50, 'line'); this.lines.setAll('checkWorldBounds', true); this.lines.setAll('outOfBoundsKill', true); this.timer = game.time.events.loop(1000, this.disco, this); and my ray-creator function: r = Math.random(); if(r < 0.5){ this.ray = this.lines.getFirstDead(); this.ray.reset(101, 20); this.ray.body.angle = -90; this.ray.body.angularVelocity = 100; } In the update function, this is what I am doing to kill the ray: if(this.ray.angle >=90){ this.ray.kill(); } The console error is error: this.ray is not defined. So my question is, how would I fix this so it would kill the ray once its angle is over 90 degrees? Link to comment Share on other sites More sharing options...
bruno_ Posted March 10, 2016 Share Posted March 10, 2016 you are having variable scope problems. Where are you declaring ray? Are you calling this.ray.kill where? in a event? Link to comment Share on other sites More sharing options...
AGoodUsername Posted March 10, 2016 Author Share Posted March 10, 2016 I got it to die by putting the this.ray = this.lines.getFirstDead(); directly after I create the group lines, but it now only creates them one at a time. Link to comment Share on other sites More sharing options...
AGoodUsername Posted March 10, 2016 Author Share Posted March 10, 2016 Just now, bruno_ said: you are having variable scope problems. Where are you declaring ray? Are you calling this.ray.kill where? in a event? I'm declaring this.ray in a function called disco, and this.ray.kill is being called in the update() function. Link to comment Share on other sites More sharing options...
bruno_ Posted March 10, 2016 Share Posted March 10, 2016 There's something out of scope/context... try to see if you need to fill the "context" parameter with "this" value in some collide, or overlap method. Phaser samples can help you with that. Link to comment Share on other sites More sharing options...
AGoodUsername Posted March 10, 2016 Author Share Posted March 10, 2016 18 minutes ago, bruno_ said: There's something out of scope/context... try to see if you need to fill the "context" parameter with "this" value in some collide, or overlap method. Phaser samples can help you with that. Add an invisible boundary sprite? Link to comment Share on other sites More sharing options...
Recommended Posts