Groundwork tutorial on movement



  • I'm sorry.
    I was able to get the blue square to appear on the screen but afterwards I get an error directed at the last bit of code.

    package;
    
    import cpp.Void;
    import flixel.FlxG;
    import flixel.FlxObject;
    import flixel.FlxSprite;
    import flixel.math.FlxPoint;
    import flixel.system.FlxSound;
    import flixel.util.FlxColor;
    import flixel.system.FlxAssets.FlxGraphicAsset;
    
    class Player extends FlxSprite
    {
    var spritePlayer:FlxSprite;
    
    public var speed:Float = 200;
    
    public function new(?X:Float = 0, ?Y:Float = 0)
    {
    	super(X, Y);
    	makeGraphic(16, 16, FlxColor.BLUE);
    	drag.x = drag.y = 1600;
    }
    
    public function movement():Void
    {
    	var _up:Bool = false;
    	var _down:Bool = false;
    	var _left:Bool = false;
    	var _right:Bool = false;
    	
    	 _up = FlxG.keys.anyPressed([UP, W]);
    	_down = FlxG.keys.anyPressed([DOWN, S]);
    	_left = FlxG.keys.anyPressed([LEFT, A]);
    	_right = FlxG.keys.anyPressed([RIGHT, D]);
    	
    	 if (_up && _down)
    		_up = _down = false;
    	if (_left && _right)
    		_left = _right = false;
    	 if (_up || _down || _left || _right)
     {
    velocity.x = speed;
    velocity.y = speed;
    
    var mA:Float = 0;
    
    if (_up)
    {
        mA = -90;
        if (_left)
        mA -= 45;
        else if (_right)
        mA += 45;
    }
    
    else if (_down)
    {
        mA = 90;
        if (_left)
        mA += 45;
        else if (_right)
        mA -= 45;
    }
    
    else if (_left)
        mA = 180;
    
    else if (_right)
        mA = 0;
    
    
    velocity.set(speed, 0);
    velocity.rotate(FlxPoint.weak(0, 0), mA);
             }
    }
    
       override public function update(elapsed:Float):Void
     {
     movement();
     super.update(elapsed);
      }
    
    }
    

    The error's showing up here.
    0_1513209164479_ugh.PNG

    and here's a bit of the output
    0_1513209208674_ugh2.PNG


  • administrators

    Remove the following line from your imports:

    import cpp.Void;
    

    This was most likely added by HaxeDevelop's auto-import.



  • @gama11
    Thanks again


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.