本文整理匯總了Java中com.badlogic.gdx.maps.tiled.TiledMapTileLayer.getTileWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java TiledMapTileLayer.getTileWidth方法的具體用法?Java TiledMapTileLayer.getTileWidth怎麽用?Java TiledMapTileLayer.getTileWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.maps.tiled.TiledMapTileLayer
的用法示例。
在下文中一共展示了TiledMapTileLayer.getTileWidth方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
@Override
public IMap<T> generateMap(TiledMap map) {
tm = map;
mainLayer = (TiledMapTileLayer) tm.getLayers().get(0);
pixelwidth = (int) (mainLayer.getWidth() * mainLayer.getTileWidth());
pixelheight = (int) (mainLayer.getHeight() * mainLayer.getTileHeight());
int resolution = (int) mainLayer.getTileWidth();
// generate the quad tree
QuadTree<T> tree = new QuadTree<T>(resolution);
QuadNode<T> headNode = generateSquare(0, 0, pixelwidth, pixelheight, tree, null);
tree.root = headNode;
headNode.genVisibilityGraph();
return tree;
}
示例2: parseMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* Parst die Map.
*
* Wird von {@link #initMap()} aufgerufen.
*/
private void parseMap()
{
TiledMapTileLayer firstLayer = (TiledMapTileLayer) tileMap.getLayers().get(0);
mapWidth = firstLayer.getWidth() * firstLayer.getTileWidth();
mapHeight = firstLayer.getHeight() * firstLayer.getTileHeight();
parseMapObjects();
parseMapCollisionTiles();
}
示例3: createBlocks
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* Creates box2d bodies for all non-null tiles
* in the specified layer and assigns the specified
* category bits.
*
* @param layer the layer being read
* @param bits category bits assigned to fixtures
*/
private void createBlocks(TiledMapTileLayer layer, short bits) {
// tile size
float ts = layer.getTileWidth();
// go through all cells in layer
for (int row = 0; row < layer.getHeight(); row++) {
for (int col = 0; col < layer.getWidth(); col++) {
// get cell
Cell cell = layer.getCell(col, row);
// check that there is a cell
if (cell == null) continue;
if (cell.getTile() == null) continue;
// create body from cell
BodyDef bdef = new BodyDef();
bdef.type = BodyType.StaticBody;
bdef.position.set((col + 0.5f) * ts / PPM, (row + 0.5f) * ts / PPM);
ChainShape cs = new ChainShape();
Vector2[] v = new Vector2[3];
v[0] = new Vector2(-ts / 2 / PPM, -ts / 2 / PPM);
v[1] = new Vector2(-ts / 2 / PPM, ts / 2 / PPM);
v[2] = new Vector2(ts / 2 / PPM, ts / 2 / PPM);
cs.createChain(v);
FixtureDef fd = new FixtureDef();
fd.friction = 0;
fd.shape = cs;
fd.filter.categoryBits = bits;
fd.filter.maskBits = B2DVars.BIT_PLAYER;
world.createBody(bdef).createFixture(fd);
cs.dispose();
}
}
}
示例4: loadLevel
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public void loadLevel(String level, boolean isServer, String name) {
this.isServer = isServer;
map = new TmxMapLoader().load(level);
TiledMapTileLayer layer = (TiledMapTileLayer) map.
getLayers().get("terrain");
VIEWPORT_WIDTH = (int) (layer.getTileWidth() * layer.getWidth());
VIEWPORT_HEIGHT = (int) (layer.getTileHeight() * layer.getHeight());
viewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, camera);
renderer = new OrthogonalTiledMapRenderer(map);
name = name.trim();
if (name.length() == 0)
name = "noname";
if (name.length() >= 10){
name = name.substring(0, 10);
}
ClientDetailsMessage clientDetails = new ClientDetailsMessage();
clientDetails.name = name;
clientDetails.protocolVersion = Constants.PROTOCOL_VERSION;
if (isServer) {
MapLayer collision = map.
getLayers().get("collision");
for(MapObject object: collision.getObjects()) {
worldManager.createWorldObject(object);
}
worldManager.addIncomingEvent(MessageObjectPool.instance.
eventPool.obtain().set(State.RECEIVED, clientDetails));
} else {
client.sendTCP(clientDetails);
}
controls = new onScreenControls();
}
示例5: RTSAbstractMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public RTSAbstractMap(RTSGame game, String tiledMapPath, boolean useFogOfWar) {
super();
this.game = game;
// Lets initialize the tiled map
tiledMap = new TmxMapLoader().load(tiledMapPath);
MapLayers mapLayers = tiledMap.getLayers();
baseLayer = (TiledMapTileLayer) mapLayers.get(BASE_LAYER_NAME);
baseLayerOverlay = (TiledMapTileLayer) mapLayers.get(BASE_LAYER_OVERLAY_NAME);
MapLayer objectsLayer = mapLayers.get(OBJECTS_LAYER_NAME);
if (objectsLayer != null)
mapObjects = objectsLayer.getObjects();
mapBatch = new SpriteBatch(100, RTSGame.game.mapShader);
// Initialize map renderer
mapRenderer = new OrthogonalTiledMapRenderer(tiledMap, mapBatch);
initializeMapGenAndRenderer();
// And now let's initialize the quadtree
map = mapGen.generateMap(tiledMap);
astar = new AStar<IBoundsObject>(map);
// Number of tiles that fit in the canvas, to render.
renderTileWidth = Gdx.graphics.getWidth() / (int) baseLayer.getTileWidth();
renderTileHeight = Gdx.graphics.getHeight() / (int) baseLayer.getTileHeight();
// Fog of war
this.useFogOfWar = useFogOfWar;
if (useFogOfWar) {
fogOfWar = new FogOfWar((int) (baseLayer.getWidth()), (int) (baseLayer.getHeight()),
(int) baseLayer.getTileWidth());
}
}
示例6: generateKeyEntity
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
protected Entity generateKeyEntity(TiledMapTileLayer layer, String keyName, boolean mirrored, float xOffset,
float yOffset) {
Vector2 keyLoc = findFirstCell(layer);
if (keyLoc == null) {
throw new IllegalArgumentException("Could not find key in layer \"" + layer.getName() + "\".");
} else {
Entity e = world.createEntity();
Position position = world.createComponent(Position.class);
position.position.x = keyLoc.x * layer.getTileWidth() + xOffset;
position.position.y = keyLoc.y * layer.getTileHeight() + yOffset;
e.addComponent(position);
Collectable collectable = world.createComponent(Collectable.class);
collectable.item = new Item(keyName, ItemType.KEY);
e.addComponent(collectable);
StaticSprite staticSprite = world.createComponent(StaticSprite.class);
staticSprite.textureRegion = layer.getCell((int) keyLoc.x, (int) keyLoc.y).getTile().getTextureRegion();
staticSprite.spriteWidth = staticSprite.textureRegion.getRegionWidth();
staticSprite.spriteHeight = staticSprite.textureRegion.getRegionHeight();
staticSprite.mirrored = mirrored;
e.addComponent(staticSprite);
Solid solid = world.createComponent(Solid.class);
solid.boundingBox = new Rectangle(position.position.x, position.position.y, staticSprite.spriteWidth,
staticSprite.spriteHeight);
e.addComponent(solid);
e.addToWorld();
e.disable();
return e;
}
}
示例7: generateExitEntity
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
protected Entity generateExitEntity(TiledMapTileLayer layer, boolean mirrored, float xOffset, float yOffset) {
Vector2 exitLoc = findFirstCell(layer);
if (exitLoc == null) {
throw new IllegalArgumentException("Could not find exit in layer \"" + layer.getName() + "\".");
} else {
Entity e = world.createEntity();
Position p = world.createComponent(Position.class);
p.position.x = exitLoc.x * layer.getTileWidth() + xOffset;
p.position.y = exitLoc.y * layer.getTileHeight() + xOffset;
e.addComponent(p);
Interactable i = world.createComponent(Interactable.class);
e.addComponent(i);
StaticSprite s = world.createComponent(StaticSprite.class);
s.textureRegion = layer.getCell((int) exitLoc.x, (int) exitLoc.y).getTile().getTextureRegion();
s.spriteWidth = s.textureRegion.getRegionWidth();
s.spriteHeight = s.textureRegion.getRegionHeight();
s.mirrored = mirrored;
e.addComponent(s);
Solid solid = world.createComponent(Solid.class);
solid.boundingBox = new Rectangle(p.position.x, p.position.y, s.spriteWidth, s.spriteHeight);
solid.invertedGravity = false;
solid.weight = 0.25f;
e.addComponent(solid);
e.addToWorld();
e.disable();
return e;
}
}
示例8: RandomLevel
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public RandomLevel(MySidekick parent, MsgHandler remote, World world) {
super(parent, EMPTY_MAP_PATH, remote);
TiledMapTileLayer tileLayer = (TiledMapTileLayer) map.getLayers().get(
C.TileLayer);
MapLayer objectLayer = map.getLayers().get(C.ObjectLayer);
TILE_WIDTH = tileLayer.getTileWidth();
TILE_HEIGHT = tileLayer.getTileHeight();
generateLevel(map.getTileSets(), tileLayer, objectLayer, world);
}
示例9: setup
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public static final void setup(TiledMap map) {
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
TILE_WIDTH = layer.getTileWidth();
TILE_HEIGHT = layer.getTileHeight();
TILES = map.getTileSets().getTileSet(0);
mEntities = new ArrayList<Entity>(20);
}
示例10: getTileWidth
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
@Override
public float getTileWidth(TiledMapTileLayer layer) {
return layer.getTileWidth() * unitScaleX;
}
示例11: getTileWidth
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
@Override
public float getTileWidth(TiledMapTileLayer layer) {
return layer.getTileWidth() * unitScaleX * 0.5f;
}
示例12: generateMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
@Override
public IMap<T> generateMap(TiledMap map) {
tm = map;
mainLayer = (TiledMapTileLayer) tm.getLayers().get(RTSAbstractMap.BASE_LAYER_NAME);
mainLayerOverlay = (TiledMapTileLayer) tm.getLayers().get(RTSAbstractMap.BASE_LAYER_OVERLAY_NAME);
int columns = mainLayer.getWidth();
int rows = mainLayer.getHeight();
GridMap<T> gridMap = new GridMap<T>(columns, rows, (int) mainLayer.getTileWidth(),
(int) mainLayer.getTileHeight());
for (int col = 0; col < columns; col++) {
for (int row = 0; row < rows; row++) {
Cell cell = mainLayer.getCell(col, row);
String type = cell.getTile().getProperties().get(PROPERTY_TYPE, "undefined", String.class);
boolean shadow = Boolean.valueOf(cell.getTile().getProperties()
.get(PROPERTY_SHADOW, "false", String.class));
if (mainLayerOverlay != null) {
// Check if there's an overlay
Cell over = mainLayerOverlay.getCell(col, row);
if (over != null && over.getTile() != null) {
String typeaux = over.getTile().getProperties().get(PROPERTY_TYPE, "none", String.class);
if (!typeaux.equals("none")) {
type = typeaux;
}
if (Boolean.valueOf(over.getTile().getProperties().get(PROPERTY_SHADOW, "false", String.class))) {
shadow = true;
}
}
}
gridMap.getCell(col, row).setTerrainType(MapProperties.getTerrainType(type));
gridMap.getCell(col, row).setShadow(shadow);
gridMap.getCell(col, row).slopev = -Integer.valueOf(cell.getTile().getProperties()
.get(PROPERTY_SLOPEV, "0", String.class));
gridMap.getCell(col, row).slopeh = Integer.valueOf(cell.getTile().getProperties()
.get(PROPERTY_SLOPEH, "0", String.class));
}
}
generateHeights(gridMap);
return gridMap;
}
示例13: Room
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public Room(Character player, GamePlay gamePlay, RoomMap roomMap) {
this.player = player;
this.gamePlay = gamePlay;
((Player) player).setRoom(this);
deviceTileMap = new HashMap<Vector2, DeviceTile>();
map = new TmxMapLoader().load(Util.ASSETS + "maps/" + roomMap.toString() + ".tmx");
floorLayer = (TiledMapTileLayer) map.getLayers().get("floor");
wallLayer = (TiledMapTileLayer) map.getLayers().get("wall");
deviceLayer = map.getLayers().get("devices");
objectLayer = (TiledMapTileLayer) map.getLayers().get("objects");
ROOM_HEIGHT = floorLayer.getHeight();
TILE_SIZE = (int) floorLayer.getTileWidth();
buildRoom();
gamePlay.getGameScreen().setRenderer(new IsometricTiledMapRenderer(map, 1f / TILE_SIZE)); // don't let this round, that is why 1 is a floatmap
if (player.getNetwork() == null) {
City playerCity = player.getCity();
List<InternetProviderNetwork> isps = new ArrayList<InternetProviderNetwork>(5);
for (Network n : playerCity.getNetworks().values()) {
if (n instanceof InternetProviderNetwork) {
isps.add((InternetProviderNetwork) n);
}
}
network = NetworkFactory.createPlayerNetwork((Player) player, playerCity, gamePlay.getInternet());
InternetProviderNetwork isp = isps.get((int) (Math.random() * isps.size()));
gamePlay.getInternet().addNetworkToInternet(network, isp);
playerCity.addNetwork(network);
network.setDeviceLimit(1);
Device device = DeviceFactory.createDevice(0, Device.DeviceType.SERVER);
HakdSprite tile = new HakdSprite(Hakd.assets.get("nTextures.txt", TextureAtlas.class).findRegion("d0"));
tile.setSize(tile.getWidth() / TILE_SIZE, tile.getHeight() / TILE_SIZE);
tile.setObject(device);
device.setTile(tile);
network.addDevice(device);
} else {
network = player.getNetwork();
}
int deviceLimit = deviceLayer.getObjects().getCount();
network.setDeviceLimit(deviceLimit);
devices = network.getDevices();
}