private void createBox2DWorldByLayer(CCTileMapLayer physicsLayer, CCTileMap physicsMap) { bool[,] Tile = extractHitboxTiles (physicsLayer, physicsMap); bool[,] Checked = new bool[(int)physicsLayer.LayerSize.Size.Width, (int)physicsLayer.LayerSize.Size.Height]; //geht das Abbild durch int CurrentWidth; CurrentWidth = 0; int LastX; LastX = 0; for (int y = 0; y < physicsLayer.LayerSize.Size.Height; y++) { for (int x = 0; x < physicsLayer.LayerSize.Size.Width; x++) { if (Tile [x, y] == false) { if (CurrentWidth > 0) { createBoxAt (LastX * (int)physicsLayer.TileTexelSize.Width * (int)physicsMap.ScaleX, ((int)physicsLayer.LayerSize.Size.Height - y - 1) * (int)physicsLayer.TileTexelSize.Height * (int)physicsMap.ScaleY, CurrentWidth * physicsLayer.TileTexelSize.Width * physicsMap.ScaleX, physicsLayer.TileTexelSize.Height * (int)physicsMap.ScaleY); } LastX = x + 1; CurrentWidth = 0; } else { CurrentWidth += 1; } } if (CurrentWidth > 0) { createBoxAt (LastX * (int)physicsLayer.TileTexelSize.Width, ((int)physicsLayer.LayerSize.Size.Height - y - 1) * (int)physicsLayer.TileTexelSize.Height, CurrentWidth * physicsLayer.TileTexelSize.Width, physicsLayer.TileTexelSize.Height); } LastX = 0; CurrentWidth = 0; } }
protected override void AddedToScene() { base.AddedToScene(); var tilemap = new CCTileMap("tilemaps/iso-test-zorder.tmx"); AddChild(tilemap); // Uncomment this to test loading from a stream reader with Release > 1.3.1.0 // // Note: the application.ContentSearchPaths.Add("tilemaps"); in AppDelegate.cs module // // Without a TileMapFileName there is no way to determine the relative offset of the backing // graphic asset so this will have to set in the tile map definition or use a search path added // to the application ContentSearchPaths ex.. application.ContentSearchPaths.Add("images"); // using (var streamReader = new StreamReader(CCFileUtils.GetFileStream("tilemaps/iso-test-zorder.tmx"))) // { // var tileMap = new CCTileMap(streamReader); // AddChild(tileMap); // } // Use the bounds to layout the positioning of our drawable assets var bounds = VisibleBoundsWorldspace; // 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); }
public static List<Platform> LoadPlatformFromLayer(CCTileMap TileMap, CCTileMapObjectGroup PlatformHolder, Container gameContainer) { List<Platform> LoadedPlatforms = new List<Platform> (); foreach (Dictionary<string,string> LayerObject in PlatformHolder.Objects) { if (LayerObject.ContainsKey ("type") == true) { if (LayerObject ["type"] == "platform") { int LoadedSpeed = 200; if (LayerObject.ContainsKey ("speed")) LoadedSpeed = Convert.ToInt32 (LayerObject ["speed"]); List<CCPoint> LoadedWaipoints = new List<CCPoint> (); LoadedWaipoints.Add (new CCPoint ((float)Convert.ToInt32 (LayerObject ["x"]) * TileMap.ScaleX, (float)Convert.ToInt32 (LayerObject ["y"]) * TileMap.ScaleY)); if (LayerObject.ContainsKey ("waypoints") == true) { foreach (string WayPointPair in LayerObject ["waypoints"].Split(new char[]{';'},StringSplitOptions.RemoveEmptyEntries)) { CCPoint TempLoadedPoint = new CCPoint (); string[] Waypoint = WayPointPair.Split (new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries); if (Waypoint.Length > 1) { TempLoadedPoint.X = LoadedWaipoints [LoadedWaipoints.Count - 1].X + (float)Convert.ToInt32 (Waypoint [0]) * TileMap.ScaleX * TileMap.TileTexelSize.Width; TempLoadedPoint.Y = LoadedWaipoints [LoadedWaipoints.Count - 1].Y + (float)Convert.ToInt32 (Waypoint [1]) * TileMap.ScaleY * TileMap.TileTexelSize.Height; } else { throw new ArgumentException ("Incorrect Waypoints"); } LoadedWaipoints.Add (TempLoadedPoint); } } LoadedPlatforms.Add (new Platform (LoadedWaipoints, LoadedSpeed, gameContainer)); } } } return LoadedPlatforms; }
protected override void AddedToScene() { base.AddedToScene (); Background = new CCSprite ("background"); Background.Scale = screenSize.Width / Background.ContentSize.Width; Map = new CCTileMap (new CCTileMapInfo ("tilemaps/bitte.tmx")); //bei einer Invocation Exception einfach ne neue Map machen //vielleicht auch mal schauen, ob die XML_Datei korrekt ist(Attribute, fehlende < etc.) //wenn die Maplayer nicht vollständig geladen werden, muss man die Compression umstellen //mapproperties if (Map.MapPropertyNamed ("Creator") != null) mapCreator = Map.MapPropertyNamed ("Creator"); if (Map.MapPropertyNamed ("Version") != null) mapVersion = Map.MapPropertyNamed ("Version"); if (Map.MapPropertyNamed ("Name") != null) mapName = Map.MapPropertyNamed ("Name"); Map.Scale = 3f; //Scale auch beim Spawnpoint ändern Map.Antialiased = false; //Map.LayerNamed ("mainlayer") pointLayer = Map.ObjectGroupNamed ("points"); Dictionary<string,string> spawnPoint = pointLayer.ObjectNamed ("SpawnPoint"); gameContainer.mainCharacter.Position = new CCPoint ((float)Convert.ToInt32 (spawnPoint ["x"]) * Map.ScaleX, (float)Convert.ToInt32 (spawnPoint ["y"]) * Map.ScaleY); gameContainer.physicsHandler.Initialize (Map.MapDimensions.Size.Width * Map.TileTexelSize.Width * Map.ScaleX, gameContainer.mainCharacter, Map.LayerNamed ("mainlayer"), Map, gameContainer); gameContainer.mainCharacter.bindToPhysicsHandler (gameContainer.physicsHandler); //Platform hinzufügen gameContainer.platformContainer.AddRange (TMXLayerDataLoader.LoadPlatformFromLayer (Map, Map.ObjectGroupNamed ("aditionallayer"), gameContainer)); gameContainer.jumpPadContainer.AddRange (TMXLayerDataLoader.LoadJumpPadFromLayer (Map, Map.ObjectGroupNamed ("aditionallayer"), gameContainer)); this.AddChild (Background, -1); this.AddChild (Map, 0); this.AddChild (gameContainer.mainCharacter.Sprite, 2); this.AddChild (gameContainer.physicsHandler.debugDrawer.DrawNode, 1); foreach (Platform knownPlatform in gameContainer.platformContainer) { this.AddChild (knownPlatform); } foreach (JumpPad knownJumpPad in gameContainer.jumpPadContainer) { this.AddChild (knownJumpPad); } //particle init PlayerMovingParticle = new GroundParticle (); this.AddChild (PlayerMovingParticle); PlayerMovingParticle.Position = gameContainer.mainCharacter.Position; }
public void Initialize(float mapSizeWidth, Character Character, CCTileMapLayer physicsLayer, CCTileMap physicsMap, Container gameContainer) { mapSizeWidth /= pixelPerMeter; gameWorld = new b2World (new b2Vec2 (0, -9.8f)); gameWorld.AllowSleep = false; //definiert den MainCharacter Character.createPhysicsBody (gameWorld); defineGround (mapSizeWidth); createBox2DWorldByLayer (physicsLayer, physicsMap); debugDrawer = new DebugDraw (); gameWorld.SetDebugDraw (debugDrawer); debugDrawer.AppendFlags (b2DrawFlags.e_shapeBit); collusionSensor = new CollusionSensor (gameContainer); gameWorld.SetContactListener (collusionSensor); }
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); }
public static List<JumpPad> LoadJumpPadFromLayer(CCTileMap TileMap, CCTileMapObjectGroup PlatformHolder, Container gameContainer) { List<JumpPad> LoadedJumpPads = new List<JumpPad> (); foreach (Dictionary<string,string> LayerObject in PlatformHolder.Objects) { if (LayerObject.ContainsKey ("type") == true) { if (LayerObject ["type"] == "jumppad") { b2Vec2 LoadedBoostVector = new b2Vec2 (); if (LayerObject.ContainsKey ("boostvec")) { string[] BoostVecData = LayerObject ["boostvec"].Split (new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries); if (BoostVecData.Length > 1) { LoadedBoostVector = new b2Vec2 ((float)Convert.ToInt32 (BoostVecData [0]), (float)Convert.ToInt32 (BoostVecData [1])); } } CCPoint LoadedPosition; LoadedPosition = new CCPoint ((float)Convert.ToInt16 (LayerObject ["x"]) * TileMap.ScaleX - JumpPad.JumpPadSize.Width / 2, (float)Convert.ToInt32 (LayerObject ["y"]) * TileMap.ScaleY - JumpPad.JumpPadSize.Height); LoadedJumpPads.Add (new JumpPad (LoadedBoostVector, LoadedPosition, gameContainer.physicsHandler.gameWorld)); } } } return LoadedJumpPads; }
/// <summary> /// Initializes a new instance of the <see cref="Client.Common.Views.RegionViewHex"/> class. /// </summary> /// <param name="region">The Region to draw.</param> public RegionViewHex(Region region) : base(region) { var tileMapInfo = new CCTileMapInfo(Common.Constants.ClientConstants.TILEMAP_FILE_HEX); m_tileMap = new CCTileMap(tileMapInfo); m_terrainLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_TERRAIN); m_buildingLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_BUILDING); m_menueLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_MENU); m_indicatorLayer = m_tileMap.LayerNamed(ClientConstants.LAYER_INDICATOR); m_drawNodes = new Dictionary<Account, CCDrawNode>(); m_childs = new Dictionary<LayerTypes, CCNode>(); m_childs[LayerTypes.Terrain] = m_tileMap.TileLayersContainer; m_childs[LayerTypes.Building] = null; m_childs[LayerTypes.Unit] = new CCNode(); m_childs[LayerTypes.Border] = new CCNode(); m_childs[LayerTypes.Indicator] = null; // new CCNode(); m_childs[LayerTypes.Menu] = null; // new CCNode(); Init(); LoadRegionViewAsync(); }
public TileDemo(string tilemapName) { tileMap = new CCTileMap(tilemapName); tileLayersContainer = tileMap.TileLayersContainer; AddChild(tileMap); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesMoved = onTouchesMoved; AddEventListener(touchListener); }
public TileDemo (System.IO.StreamReader tilemapReader ) { tileMap = new CCTileMap(tilemapReader); tileLayersContainer = tileMap.TileLayersContainer; AddChild(tileMap); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesMoved = onTouchesMoved; AddEventListener(touchListener); }
public TileMapPropertyFinder (CCTileMap tileMap) { this.tileMap = tileMap; }
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 PathFinder(CCTileMap setMap) { map = setMap; mapLayer = map.LayerNamed("Map"); }
private bool[,] extractHitboxTiles(CCTileMapLayer physicsLayer, CCTileMap physicsMap) { bool[,] Tile = new bool[(int)physicsLayer.LayerSize.Size.Width, (int)physicsLayer.LayerSize.Size.Height]; //erstellt ein bool Abbild der Map Dictionary<string,string> tileProperties; for (int x = 1; x < physicsLayer.LayerSize.Size.Width - 1; x++) { for (int y = 1; y < physicsLayer.LayerSize.Size.Height - 1; y++) { //wenn das tile allein steht, dann ist es ein Element der Hitbox tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y)).Gid); if (tileProperties != null) { tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x - 1, y)).Gid); if (tileProperties == null) { Tile [x, y] = true; } tileProperties = null; tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x + 1, y)).Gid); if (tileProperties == null) { Tile [x, y] = true; } tileProperties = null; tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y - 1)).Gid); if (tileProperties == null) { Tile [x, y] = true; } tileProperties = null; tileProperties = physicsMap.TilePropertiesForGID (physicsLayer.TileGIDAndFlags (new CCTileMapCoordinates (x, y + 1)).Gid); if (tileProperties == null) { Tile [x, y] = true; } tileProperties = null; } } } return Tile; }
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); }
void loadTileMap() { //加载tiledmap预处理 mLevelTest = new CCTileMap ("LevelTest.tmx"); mLevelTest.Antialiased = false; mTiledLayer = mLevelTest.LayerNamed("BrickLayer"); gameplayLayer.AddChild (mTiledLayer); //初始化地图 levelCollision = new LevelCollision (); levelCollision.PopulateFrom (mLevelTest); }
private void LoadLevel(int levelNumber) { //读取瓦片地图 currentLevel = new CCTileMap ("level" + levelNumber + ".tmx"); currentLevel.Antialiased = false; //backgroundLayer是游戏中不动的背景图, 每个currentLevel都有一个对应的backgroundLayer, currentLevel中的其他部分随画面滚动 backgroundLayer = currentLevel.LayerNamed ("Background"); // CCTileMap is a CCLayer, so we'll just add it under all entities this.AddChild (currentLevel); //levelCollision 是确定地图中哪些部分是游戏人物不可以进入的 levelCollision = new LevelCollision (); levelCollision.PopulateFrom (currentLevel); // put the game layer after this.RemoveChild(gameplayLayer); this.AddChild(gameplayLayer); this.RemoveChild (hudLayer); this.AddChild (hudLayer); }
public void PopulateFrom(CCTileMap tileMap) { //得到瓦片地图里面的瓦片信息,比如说哪些瓦片可以与entity接触,具体是瓦片的哪个方向的面可以接触 //每个小瓦片的边长加上0.5的误差 tileDimension = (int)(tileMap.TileTexelSize.Width + .5f); TileMapPropertyFinder finder = new TileMapPropertyFinder (tileMap); foreach (var propertyLocation in finder.GetPropertyLocations()) { //如果在这个位置的瓦片是一个固体 if (propertyLocation.Properties.ContainsKey ("SolidCollision")) { //worldX worldY 是每个瓦片的中心的坐标 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是把整个瓦片地图按每个瓦片的左边的坐标进行排序的list //在每一个左边坐标有一列的瓦片 //debug看一下 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; //15 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. // 一开始小瓦片的方向valueToAssign可能是所有的方向,每次减去一种不可能的方向值,最后得到的就是正确的方向的值的和 //direction是这个实体瓦片暴露在外,可以与entity接触的方向 //比如说瓦片地图里的地面,方向就为up 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); } } }
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); }