本文整理匯總了Java中com.badlogic.gdx.maps.tiled.TiledMapTileLayer.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java TiledMapTileLayer.getWidth方法的具體用法?Java TiledMapTileLayer.getWidth怎麽用?Java TiledMapTileLayer.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.maps.tiled.TiledMapTileLayer
的用法示例。
在下文中一共展示了TiledMapTileLayer.getWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
@Override
public void update(final long elapsedTime) {
timeInAnimation = (timeInAnimation + elapsedTime) % getTotalAnimationTimeMs();
final int frameIndex = (int) (timeInAnimation / timePerFrameMs);
TiledMapTile currentTile = tileFrames.get(indexOrder[frameIndex]);
for (MapLayer layer : tiledMap.getLayers()) {
TiledMapTileLayer tiledMapLayer = (TiledMapTileLayer) layer;
for (int x = 0; x < tiledMapLayer.getWidth(); x++) {
for (int y = 0; y < tiledMapLayer.getHeight(); y++) {
final TiledMapTileLayer.Cell cell = tiledMapLayer.getCell(x, y);
if (cell != null) {
TiledMapTile tile = cell.getTile();
final MapProperties tileProperties = tile.getProperties();
if (tileProperties.containsKey(JRPG_TILE_ANIMATION_ID)
&& tileProperties.get(JRPG_TILE_ANIMATION_ID).equals(id)) {
cell.setTile(currentTile);
}
}
}
}
}
}
示例2: getDoorTiles
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
private List<MapTile> getDoorTiles(final TiledMapTileLayer layer) {
final List<MapTile> mapTiles = new LinkedList<>();
final int layerIndex = layer.getProperties().get(GameMap.MAP_LAYER_PROP_MAP_LAYER, 0, Integer.class);
for (int x = 0; x < layer.getWidth(); x++) {
for (int y = 0; y < layer.getHeight(); y++) {
final TiledMapTileLayer.Cell cell = layer.getCell(x, y);
TiledMapTile tile = (cell != null) ? cell.getTile() : null;
if (tile != null && tile.getProperties().get(JRPG_TILE_IS_DOOR, false, Boolean.class)) {
mapTiles.add(new MapTile(
new TileCoordinate(x, y, layerIndex),
layer.getName(),
tile
));
}
}
}
return mapTiles;
}
示例3: initSolidTiles
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
private void initSolidTiles(TiledMap map){
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get("CollisionTiles");
for(int x = 0; x < layer.getWidth(); x++){
for(int y = 0; y < layer.getHeight(); y++){
Cell cell = layer.getCell(x, y);
if(cell == null){
solids[x][y] = false;
continue;
}
if(cell.getTile() == null){
solids[x][y] = false;
continue;
}
else{
solids[x][y] = true;
}
}
}
}
示例4: createL0Animation
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public void createL0Animation(Texture tileTexture, String tag){
//hardcoded grass texture region
Tile = new Array<StaticTiledMapTile>();
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32)));
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0);
for(int x = 0; x < layer.getWidth();x++){
for(int y = 0; y < layer.getHeight();y++){
TiledMapTileLayer.Cell cell = layer.getCell(x,y);
Object property = cell.getTile().getProperties().get(tag);
if(property != null){
cell.setTile(new AnimatedTiledMapTile(1.5f,Tile));
}
}
}
}
示例5: createL1SmallAnimation
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public void createL1SmallAnimation(Texture tileTexture, String tag){
//hardcoded grass texture region
Tile = new Array<StaticTiledMapTile>();
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32)));
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1);
for(int x = 0; x < layer.getWidth();x++){
for(int y = 0; y < layer.getHeight();y++){
TiledMapTileLayer.Cell cell = layer.getCell(x,y);
if(cell!=null && cell.getTile().getProperties().get(tag)!=null){
cell.setTile(new AnimatedTiledMapTile(1.5f,Tile));
}
}
}
}
示例6: createL1LargeAnimation
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public void createL1LargeAnimation(Texture tileTexture, String tag){
//hardcoded grass texture region
Tile = new Array<StaticTiledMapTile>();
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,64,64)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,64,64)));
Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,128,0,64,64)));
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1);
for(int x = 0; x < layer.getWidth();x++){
for(int y = 0; y < layer.getHeight();y++){
TiledMapTileLayer.Cell cell = layer.getCell(x,y);
if(cell!=null && cell.getTile().getProperties().get(tag)!=null){
cell.setTile(new AnimatedTiledMapTile(1.5f,Tile));
}
}
}
}
示例7: 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;
}
示例8: ScrollMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
*
* @param tileMap ширина, высота и размер тайла берется из первого слоя:
* TiledMapTileLayer bg = (TiledMapTileLayer) tileMap.getLayers().get(0);
* cellSize = (int) bg.getTileHeight(); mapW = bg.getWidth(); mapH =
* bg.getHeight();
*/
public ScrollMap(TiledMap tileMap) {
mapCamera = new OrthographicCamera();
mapRenderer = new OrthogonalTiledMapRenderer(tileMap, 1f/* / cellSize */);
stageViewport = new ScreenViewport(new OrthographicCamera());
TiledMapTileLayer bg = (TiledMapTileLayer) tileMap.getLayers().get(0);
cellSize = (int) bg.getTileHeight();
mapW = bg.getWidth() * cellSize;
mapH = bg.getHeight() * cellSize;
mapHolder = new Actor();
mapHolder.setSize(mapW, mapH);
scrollPane = new ScrollPane(mapHolder);
scrollPane.setOverscroll(false, false);
root = new Table();
root.setFillParent(true);
root.add(scrollPane).fill().expand();
stage = new Stage(stageViewport);
stage.addActor(root);
im = new InputMultiplexer();
gameBatch = mapRenderer.getSpriteBatch();
sprites = new Array<Sprite>();
gestureDetector = new GestureDetector(gestureListener);
}
示例9: generateCollisionArray
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* <p>
* Scans every cell in the layer and indiscriminately marks it as solid in a
* collision map, and returns the map.
* </p>
*
* @param layer
* The layer to use to generate the map.
* @param mirrorLayer
* The mirror layer corresponding to the layer.
* @return A boolean array where map[layer.getWidth() * y + x] is a cell,
* and true means "solid".
*/
public static ArrayList<Integer> generateCollisionArray(TiledMapTileLayer layer, TiledMapTileLayer mirrorLayer) {
ArrayList<Integer> collisionMap = new ArrayList<Integer>();
collisionMap.ensureCapacity((layer.getWidth() + mirrorLayer.getWidth()) * layer.getHeight());
for (int y = 0; y < layer.getHeight(); y++) {
for (int x = 0; x < (layer.getWidth() + mirrorLayer.getWidth()); x++) {
if (x < layer.getWidth()) {
collisionMap.add((layer.getCell(x, y) != null ? 1 : 0));
} else {
collisionMap.add((mirrorLayer.getCell(x - layer.getWidth(), y) != null ? 1 : 0));
}
}
}
return collisionMap;
}
示例10: findFirstCell
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* <p>
* Finds the first non-null cell in a layer. Only really meaningful in some
* layers.
* </p>
* <p>
* Cells are searched across x before y is incremented.
* </p>
*
* @param layer
* The layer whose cell we'll find.
* @return An initialised {@link Vector2} with the x and y coordinates (in
* tile coordinates), or null if the layer is empty. x is right, y
* is down.
*/
public static Vector2 findFirstCell(TiledMapTileLayer layer) {
for (int y = 0; y < layer.getHeight(); y++) {
for (int x = 0; x < layer.getWidth(); x++) {
if (layer.getCell(x, y) != null) {
// found first
Vector2 retVal = new Vector2();
retVal.x = (float) x;
retVal.y = (float) y;
return retVal;
}
}
}
return null;
}
示例11: loadMap
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public static void loadMap(String fileName) {
TiledMap map = new TmxMapLoader().load(fileName);
for (int i = 0; i < map.getLayers().getCount(); i++) {
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers()
.get(i);
for (int x = 0; x < layer.getWidth(); x++) {
for (int y = 0; y < layer.getHeight(); y++) {
Cell cell = layer.getCell(x, layer.getHeight() - 1 - y);
if (cell == null) {
continue;
}
Entity e = EntityManager.createTile((String) cell.getTile()
.getProperties().get("name"), x * 16, y * 16);
EntityManager.setEntityLayer(e, Name.LAYER_FLOOR);
}
}
}
}
示例12: loadLayer
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
public void loadLayer(int layerNo){
Scene.log("Tiles Layer no: "+layerNo);
TiledMapTileLayer layer = (TiledMapTileLayer)mlayers.get(layerNo);
NoOfColumns = layer.getWidth();
Scene.log("MapColumns: "+NoOfColumns);
NoOfRows = layer.getHeight();
Scene.log("MapRows: "+NoOfRows);
tiles .add(new MapActor[NoOfRows][NoOfColumns]);
for(int i=0; i<NoOfRows; i++)
for(int j=0; j<NoOfColumns; j++){
Cell c = layer.getCell(j, i);
if(c != null){
tiles.get(layerNo)[i][j] = new MapActor(c.getTile().getTextureRegion(),
i, j, c.getTile().getId(), tileSize);
addActor(tiles.get(layerNo)[i][j]);
}
else{
tiles.get(layerNo)[i][j] = new MapActor((TextureRegion)null,i, j, 0, tileSize);
addActor(tiles.get(layerNo)[i][j]);
}
}
mapWidth = tileSize * NoOfColumns;
mapHeight = tileSize * NoOfRows;
//Stage.mapOffsetX = mapWidth - Stage.camOffsetX;
//Stage.mapOffsetY = mapHeight - Stage.camOffsetYTop;
}
示例13: animateTiles
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* Make the tiles containing 'animation' key animated.
* @param layer
*/
private void animateTiles(TiledMapTileLayer layer) {
for (int x = 1; x < layer.getWidth(); x++) {
for (int y = 1; y < layer.getHeight(); y++) {
Cell cell = layer.getCell(x, y);
if(cell != null) {
TiledMapTile oldTile = cell.getTile();
if(oldTile.getProperties().containsKey("animation")) {
String animation = (String) oldTile.getProperties().get("animation");
float speed = 0.15f;
if(oldTile.getProperties().containsKey("speed")) {
speed = Float.parseFloat((String) oldTile.getProperties().get("speed"));
}
AnimatedTiledMapTile newTile = new AnimatedTiledMapTile(speed,
Tiles.getAnimatedTile(animation));
newTile.getProperties().putAll(oldTile.getProperties());
cell.setTile(newTile);
}
}
}
}
}
示例14: initTileset
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; //導入方法依賴的package包/類
/**
* Tiles that have a 'texture' property will be using an optimized tileset. This is to avoid screen tearing.
* @param layer
*/
private void initTileset(TiledMapTileLayer layer) {
ArrayMap<String, TextureRegion> textureArr = new ArrayMap<String, TextureRegion>();
for(int x = 0; x < layer.getWidth(); x++) {
for(int y = 0; y < layer.getHeight(); y++) {
Cell cell = layer.getCell(x, y);
if(cell != null) {
TiledMapTile oldTile = cell.getTile();
if(oldTile.getProperties().containsKey("texture")) {
//D.o("Initializing textures");
String texture = (String) oldTile.getProperties().get("texture");
if(textureArr.containsKey(texture)) {
oldTile.getTextureRegion().setRegion(textureArr.get(texture));
}
else {
TextureRegion t = Tiles.getTile(texture);
textureArr.put(texture, t);
oldTile.getTextureRegion().setRegion(t);
}
}
}
}
}
}
示例15: 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();
}