HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

FlxSprite has no field drawCircle #1533

Closed Sekhmet closed 9 years ago

Sekhmet commented 9 years ago

Hi. I'm beginner at Haxe and HaxeFlixel and now I'm trying to create circle on sprite, but I'm receiving following error flixel.FlxSprite has no field drawCircle

My code is:

var chain:FlxSprite = new FlxSprite();
chain.makeGraphic(FlxG.width, FlxG.height, FlxColor.TRANSPARENT, true);
chain.drawCircle(FlxG.width/2, FlxG.height/2, radius, FlxColor.CRIMSON, lineStyle, fillStyle);
add(chain);

I can get it working by calling FlxSpriteUtil.drawCircle but how do I do it with such syntax above?

I see that others are using almost same code and it's working for them.

Haxe version 3.1.3

Gama11 commented 9 years ago

This syntax is achieved by using a Haxe feature called static extension. You need to add:

using flixel.util.FlxSpriteUtil;

to the imports section of your module.

jonfreynik commented 4 years ago

Sorry for beating a dead horse - I don't want to open an issue because I'm sure this is user error and my error is similar to the one mentions ... I've started moving my custom Sprite drawings into separate classes and everything has broken. As an example I have the following code.

package tiles;

import flixel.FlxSprite;
import flixel.util.FlxColor;
using flixel.util.FlxSpriteUtil;

class DynamicBlock extends FlxSprite {

    public function new(x:Float, y:Float) {
        super(x, y);
        makeGraphic(32, 32, FlxColor.TRANSPARENT);
        drawCircle(32, 32, 4, FlxColor.WHITE);
    }
}

When I try to compile it gives me the error Unknown identifier : drawCircle for the class ... I'm sure I'm doing something stupid but was hoping I might get some help from the pros.

Gama11 commented 4 years ago

@jfreynik That is actually a recent breaking change in Haxe 4. Static extensions no longer work through implicit this access. To work around this, simply prefix this.

jonfreynik commented 4 years ago

@Gama11 - Lifesaver! Thank you 👍