Help with file select screen



  • I'm trying to make a little file select screen somewhat like The legend of zelda

    My problem is the white square placeholder that I'll use as a cursor doesn't move when I press up (haven't done down yet)

    In console it says which spot it SHOULD be in, but it doesn't show it there.

    Here's my code, with all the non-selection stuff out for cleanliness

    {
    	public var whiteSquare:FlxSprite;
    	private var Y:Int;
    	override public function create():Void
    	{
    		var whiteSquare = new FlxSprite(55, 55);
    		whiteSquare.makeGraphic(16, 16, FlxColor.WHITE);
    		add(whiteSquare);
    		
    		var Y:Int = 1;
    		super.create();
    	}
    	
    	override public function update(elapsed:Float):Void 
    	{
    		
    		if (FlxG.keys.anyJustPressed([UP, W]))
    		{
    			Y -= 1;
    			if (Y <= 0)
    			{
    				Y = 3;
    			}
    			FlxG.log.add("fasd");
    			if (Y == 1)
    			{
    				FlxG.log.add("1");
    				whiteSquare.y += 100;
    				
    			}
    			if (Y == 2)
    			{
    				FlxG.log.add("2");
    				whiteSquare.y -= 45;
    			}
    			if (Y == 3)
    			{
    				FlxG.log.add("3");
    				whiteSquare.y -= 55;
    			}
    		}
    		
    		super.update(elapsed);
    	}
    


  • as far as I can see ... you are not even initializing the whitSquare variable right. since you are creating a new local variable in the create() function using the var keyword. so I can't see where is the public variable initialized.

    I would also advice against using relative values when moving the cursor. because then you wouldn't be able to tell when a position is wrong quickly since errors are accumulated. so something like whiteSquare.y = 155; is better



  • 'Var' is for declaring a new variable. Look at the fixed version and compare to yours:

    	super.create();
    
    	whiteSquare = new FlxSprite(55, 55);
    	whiteSquare.makeGraphic(16, 16, FlxColor.WHITE);
    	whiteSquare.updateHitbox();
    	add(whiteSquare);
    
    	Y = 1;
    


  • @Ali-Hassan said in Help with file select screen:

    as far as I can see ... you are not even initializing the whitSquare variable right. since you are creating a new local variable in the create() function using the var keyword. so I can't see where is the public variable initialized.

    Ahh, that was it, all I had to do was remove the var before whiteSquare and it fixed my problem!

    I would also advice against using relative values when moving the cursor. because then you wouldn't be able to tell when a position is wrong quickly since errors are accumulated. so something like whiteSquare.y = 155; is better

    That was just a thing I was testing out right before I posted the code to the forum, forgot to change it, but I'll definitely keep that in mind!


Log in to reply
 

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