Tile/Tilemap strange visibility glitch

I took a sprite sheet of 7 frames (character running animation) and put it in a Tile array. For some strange reason, I can toggle the visibility of each frame (on or off) unless it is placed inside a conditional (if/then), in which case it stays on the scree even though the trace reveals that visibility is false. Any ideas why?

char[0].visible = false; //works!

s = 10;
if (s > 2) {
   char[0].visible = false; //trace's as false, but remains on screen
}

This seems to work:

package;


import openfl.display.BitmapData;
import openfl.display.Sprite;
import openfl.display.Tilemap;
import openfl.display.Tileset;
import openfl.display.Tile;
import openfl.events.Event;
import openfl.geom.Rectangle;


class Main extends Sprite {
	
	
	public function new () {
		
		super ();
		
		var bitmapData = new BitmapData (350, 100, true);
		
		var tileset = new Tileset (bitmapData);
		var tilemap = new Tilemap (stage.stageWidth, stage.stageWidth, tileset);
		
		var rect, alpha, color, tile;
		var tiles = [];
		
		for (i in 0...7) {
			
			rect = new Rectangle (50 * i, 0, 50, 100);
			alpha = Math.round (0xFF * (1 / (7 - i)));
			color = (alpha << 24) | 0x00FF0000; 
			
			bitmapData.fillRect (rect, color);
			tileset.addRect (rect);
			
			tile = new Tile (i, 50 * i, 0);
			
			tilemap.addTile (tile);
			tiles.push (tile);
			
		}
		
		addChild (tilemap);
		
		var frame = 0;
		
		addEventListener (Event.ENTER_FRAME, function (_) {
			
			for (i in 0...7) {
				
				if (i == frame) {
					
					tiles[i].visible = true;
					
				} else {
					
					tiles[i].visible = false;
					
				}
				
			}
			
			frame++;
			
			if (frame > 6) {
				
				frame = 0;
				
			}
			
		});
		
	}
	
	
}

Are you using the latest version of OpenFL?

1 Like

Unreal… It was just a matter of updating OpenFL (I’d only been coding for a month… didn’t think I’d need to…) Thanks Sing!

1 Like