Tile Block to Sprite?



  • How do I do this again? I know it's possible right?

    I have a tile set acting as walls. It tiles out perfectly. However, I remembered I need those walls to act as actual objects so I can track their health.

    This can be done right?





  • Well. This is what I'm doing:

    //Walls
    private function buildWall():Void
    {
    	// Can't place towers on GUI
    	if (FlxG.mouse.y > FlxG.height - 16) return;
    	
    	// Can't buy towers without money
    	if (money < wallPrice) {
    		
    		escapeBuilding();
    		return;
    	}
    	
    	// Snap to grid
    	var xPos:Float = FlxG.mouse.x - (FlxG.mouse.x % 12);
    	var yPos:Float = FlxG.mouse.y - (FlxG.mouse.y % 12);
    	
    	
    	// Can't place towers on other Structures
    	for (i in 0...baseGroup.length) {
    		var structure:FlxSprite = baseGroup.members[i];
    		//if (structure.x == xPos && structure.y == yPos && structure.exists) 
    		if (structure.x == xPos && structure.y == yPos) 
    		{
    			if (baseGroup.members.length  > 0)
    			{
    				escapeBuilding();
    				return;
    			}				
    		}
    	}			
    	
    	if (buildHelper.overlaps(WallMap))
    	{
    		escapeBuilding();
    		return;
    	}
    	
    	// Get data map coordinate
    	var mx:Int = Std.int(FlxG.mouse.screenX / 12);
    	var my:Int = Std.int(FlxG.mouse.screenY / 12);
    		
    	// Change tile toogle
    	WallMap.setTile(mx, my, 1 - WallMap.getTile(mx, my), true);
    	
    	var vall:FlxSprite = WallMap.tileToSprite(Std.int(mx), Std.int(my), -1);
    	vall.width = 12;
    	vall.height = 12;
    	add(vall);
    	
    	var wall:Wall = new Wall(xPos, yPos, wallGroup);	
    	wall.loadGraphic(vall.graphic);
    	vall.kill();		
    	
    	wall.index = wallGroup.length - 1;
    	wallGroup.add(wall); 
    	baseGroup.add(wall);
    	
    	
    
    	
    	money -= wallPrice;
    	//wallPrice += cast(wallPrice * 0.1);
    	wallButton.text = "Buy [E]Wall ($" + wallPrice + ")";
    	escapeBuilding();
    	
    	//FlxG.play("Build1");
    }
    

    And THIS is what I'm getting:
    warped

    Any ideas how to fix?


Log in to reply
 

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