I have a ‘ball’ class that defines a set of on-screen circles, one within the other (a ‘ball’ with a black outline below it).
I’d like to be able to resize both of these circles within my main code (using an event listener that updates every frame). Unfortunately I can’t see how to do this in the function that handles the update event.
Here’s the code for my ball class:
package;
import openfl.display.Sprite;
class Ball extends Sprite
{
public var z : Float;
public var Xvel : Float;
public var Yvel : Float;
public var Zvel : Float;
public function new()
{
super();
graphics.beginFill(0x000000);
graphics.drawCircle(4, 4, 5);
graphics.endFill();
this.graphics.beginFill(0xffa500);
this.graphics.drawCircle(4, 4, 4);
this.graphics.endFill();
this.z = 0.0;
this.Xvel = 0.0;
this.Yvel = 0.0;
this.Zvel = 0.0;
}
}
The ball is added to the display in the init function. I’d like to then update it’s appearance in a function that runs every frame:
private function everyFrame(event:Event):Void {
if (ball.z > 100){
//determine apparent size of ball
var apparent = 8 * (ball.z / 100);
}
My hope is to use the variable ‘apparent’ to set the size of the ball to be displayed.
My question is therefore in two parts;
- Is it possible to set both circles that comprise the ball to be updated with a single call, or do I need to update both parts separately?
- Can I update the size of the ball here, or do I need to remove (removeChild) it, resize it, then redraw (addChild) it each frame?