private void LoadLevel(int levelNumber) { currentLevel = new CCTileMap("level" + levelNumber + ".tmx"); currentLevel.Antialiased = false; backgroundLayer = currentLevel.LayerNamed("Background"); // CCTileMap is a CCLayer, so we'll just add it under all entities this.AddChild(currentLevel); // put the game layer after this.RemoveChild(gameplayLayer); this.AddChild(gameplayLayer); this.RemoveChild(hudLayer); this.AddChild(hudLayer); }
private void AddBoard() { var boardPath = "tilemaps/board.tmx"; var set = settings["chess-set"]; var chessSet = JsonConvert.DeserializeObject <ChessSet>(set); if (chessSet != null && !string.IsNullOrEmpty(chessSet.BoardPath)) { boardPath = chessSet.BoardPath; } this.tileMap = new CCTileMap(boardPath); this.scaleFactor = this.ContentSize.Width / tileMap.TileLayersContainer.ContentSize.Width; this.tileMap.Scale = scaleFactor; tileMap.PositionX = Origin.X; tileMap.PositionY = Origin.Y; tileMap.AnchorPoint = new CCPoint(0, 0); tileMap.Antialiased = false; this.AddChild(tileMap, -1); }
protected override void AddedToScene() { base.AddedToScene(); // Use the bounds to layout the positioning of our drawable assets var bounds = VisibleBoundsWorldspace; var tilemap = new CCTileMap("tilemaps/iso-test-zorder"); // Load user submitted tilemap //var tilemap = new CCTileMap("tilemaps/test"); AddChild(tilemap); // position the label on the center of the screen label.Position = bounds.Center; // Register for touch events var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener(touchListener, this); }
protected override void AddedToScene() { base.AddedToScene(); CCPoint center = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2); tileMap = new CCTileMap("tilemaps/level0.tmx"); this.AddChild(tileMap); stationCore = new CoreStation(); stationCore.PositionX = center.X / 2.0f; stationCore.PositionY = center.Y / 2.0f; stationCore.SetDesiredPositionToCurrentPosition(); AddChild(stationCore); tileMap.TileLayersContainer.RunAction(new CCFollow(stationCore, new CCRect(0, 0, 5000.0f, 5000.0f))); // Use the bounds to layout the positioning of our drawable assets CCRect bounds = VisibleBoundsWorldspace; }
public void PopulateFrom(CCTileMap tileMap) { tileDimension = (int)(tileMap.TileTexelSize.Width + .5f); TileMapPropertyFinder finder = new TileMapPropertyFinder(tileMap); foreach (var propertyLocation in finder.GetPropertyLocations()) { if (propertyLocation.Properties.ContainsKey("SolidCollision")) { float centerX = propertyLocation.WorldX; float centerY = propertyLocation.WorldY; float left = centerX - tileDimension / 2.0f; float bottom = centerY - tileDimension / 2.0f; RectWithDirection rectangle = new RectWithDirection { Left = left, Bottom = bottom, Width = tileDimension, Height = tileDimension }; collisions.Add(rectangle); } } // Sort by XAxis to speed future searches: collisions = collisions.OrderBy(item => item.Left).ToList(); // now let's adjust the directions that these point for (int i = 0; i < collisions.Count; i++) { var rect = collisions[i]; // By default rectangles can reposition objects in all directions: int valueToAssign = (int)Directions.All; float centerX = rect.CenterX; float centerY = rect.CenterY; // If there are collisions on the sides, then this // rectangle can no longer repositon objects in that direction. if (HasCollisionAt(centerX - tileDimension, centerY)) { valueToAssign -= (int)Directions.Left; } if (HasCollisionAt(centerX + tileDimension, centerY)) { valueToAssign -= (int)Directions.Right; } if (HasCollisionAt(centerX, centerY + tileDimension)) { valueToAssign -= (int)Directions.Up; } if (HasCollisionAt(centerX, centerY - tileDimension)) { valueToAssign -= (int)Directions.Down; } rect.Directions = (Directions)valueToAssign; collisions[i] = rect; } for (int i = collisions.Count - 1; i > -1; i--) { if (collisions[i].Directions == Directions.None) { collisions.RemoveAt(i); } } }
public PhysicsEngine(string mapname) { this.Tilemap = new CCTileMap("maps/" + mapname + ".tmx"); this.PopulateFrom(this.Tilemap); }
public TileMapPropertyFinder(CCTileMap tileMap) { this.tileMap = tileMap; }