本文整理匯總了Java中com.badlogic.gdx.maps.MapLayer.getObjects方法的典型用法代碼示例。如果您正苦於以下問題:Java MapLayer.getObjects方法的具體用法?Java MapLayer.getObjects怎麽用?Java MapLayer.getObjects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.maps.MapLayer
的用法示例。
在下文中一共展示了MapLayer.getObjects方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: load
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
public void load(TiledMap map) {
MapProperties properties = map.getProperties();
width = (Integer) properties.get(Tmx.WIDTH);
height = (Integer) properties.get(Tmx.HEIGHT);
objects = new MapObject[width][height];
portals.clear();
for (MapLayer layer : map.getLayers()) {
for (MapObject object : layer.getObjects()) {
if (object.getProperties().get("portal-id") != null) {
portals.put((String) object.getProperties().get("portal-id"), object);
}
MapProperties objectProperties = object.getProperties();
float x = (Float) objectProperties.get("x");
float y = (Float) objectProperties.get("y");
int indexX = (int) Math.floor(x / GameConfig.CELL_SCALE);
int indexY = (int) Math.floor(y / GameConfig.CELL_SCALE);
if (indexX >= 0 && indexY >= 0 && indexX < width && indexY < height) {
objects[indexX][indexY] = object;
}
}
}
}
示例2: loadCharacterGroups
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private void loadCharacterGroups() throws IOException {
MapLayer groupsLayer = map.getLayers().get(LAYER_GROUPS);
if (groupsLayer == null) {
return;
}
MapObjects groups = groupsLayer.getObjects();
for (MapObject mapGroup : groups) {
if (mapGroup.getName() == null) {
continue;
}
String groupFile = mapGroup.getName();
String id = (String) mapGroup.getProperties().get(PROPERTY_ID);
if (id == null) {
id = groupFile;
}
Vector2 position = getPositionFromMapObject(mapGroup);
CharacterGroupGameObject group = new CharacterGroupGameObject(id, Gdx.files.internal(Configuration
.getFolderGroups() + groupFile + ".xml"), gameMap);
group.position().set((int) (position.x / gameMap.getTileSizeX()),
(int) (position.y / gameMap.getTileSizeY()));
}
}
示例3: loadItems
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private void loadItems() throws IOException {
MapLayer itemsLayer = map.getLayers().get(LAYER_ITEMS);
if (itemsLayer == null) {
return;
}
MapObjects items = itemsLayer.getObjects();
for (MapObject item : items) {
Vector2 position = getPositionFromMapObject(item);
PickableGameObject newItem = new PickableGameObject(item.getName());
newItem.getOwner().set(item.getProperties().get(PROPERTY_OWNER_CHARACTER, String.class),
Faction.getFaction(item.getProperties().get(PROPERTY_OWNER_FACTION, String.class)),
Boolean.valueOf(item.getProperties().get(PROPERTY_OWNER_FIXED, "false", String.class)));
newItem.position().set(position.x / gameMap.getTileSizeX(), position.y / gameMap.getTileSizeY());
newItem.setMap(gameMap);
newItem.setOffsets(newItem.getXOffset() + getInteger(item, PROPERTY_XOFFSET, 0) * gameMap.getScaleX(),
newItem.getYOffset() + getInteger(item, PROPERTY_YOFFSET, 0) * gameMap.getScaleY());
}
}
示例4: loadLocations
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private void loadLocations(MapLayer locationsLayer, boolean loadTraps) throws IOException {
if (locationsLayer == null) {
return;
}
MapObjects locations = locationsLayer.getObjects();
for (MapObject location : locations) {
String locId = location.getProperties().get(PROPERTY_ID, location.getName(), String.class)
.toLowerCase(Locale.ENGLISH);
String locType = location.getName();
SaveablePolygon locPolygon = transformTiledPolygon(gameMap, getPolygonFromMapObject(location));
GameLocation newLocation = loadTraps ? new TrapLocation(locId, locType, locPolygon,
Boolean.valueOf(location.getProperties().get(PROPERTY_DETECTED, "false", String.class)),
Boolean.valueOf(location.getProperties().get(PROPERTY_DISARMED, "false", String.class)))
: new GameLocation(locId, locType, locPolygon);
newLocation.setMap(gameMap);
newLocation.loadFromXML(Gdx.files.internal(Configuration.getFolderLocations() + locType + ".xml"));
}
for (GameObject go : gameMap.gameObjects) {
if (go instanceof GameCharacter) {
((GameCharacter) go).calculateCurrentLocations();
}
}
}
示例5: loadTransitions
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private void loadTransitions() {
MapLayer locationsLayer = map.getLayers().get(LAYER_TRANSITIONS);
if (locationsLayer == null) {
return;
}
Array<Transition> transitions = new Array<Transition>();
MapObjects locations = locationsLayer.getObjects();
for (MapObject location : locations) {
MapObject mapObject = (MapObject) location;
String[] coords = ((String) mapObject.getProperties().get(PROPERTY_TARGET)).split(",");
Tile target = new Tile(Integer.parseInt(coords[0].trim()), Integer.parseInt(coords[1].trim()));
Polygon polygon = getPolygonFromMapObject(mapObject);
Transition newTransition = new Transition(gameMap, mapObject.getName(), target.getX(), target.getY(),
transformTiledPolygon(gameMap, polygon));
transitions.add(newTransition);
}
buildTransitionTiles(transitions);
}
示例6: loadLevelObjects
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
public void loadLevelObjects() {
MapLayer mapLayerMission = getMap().getLayers().get(LAYER_MISSIONOBJECTS);
MapObjects objects = mapLayerMission.getObjects();
for (int i = 0; i < objects.getCount(); i++) {
MapObject mapObj = objects.get(i);
SpawnableBase base = EntityFactory.getEntity(mapObj.getName());
if (base != null) {
base.prepareFromMap(getLevelID(), mapObj);
}
}
Logger.dbg("map objects loaded!");
}
示例7: render
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
public void render(){
beginRender();
int layerCourant = 0;
for(MapLayer layer : map.getLayers()){
if(layer instanceof TiledMapTileLayer){
renderTileLayer((TiledMapTileLayer)layer);
layerCourant++;
if(layerCourant==numberOfSpriteLayer){//if we are in the layer for the Sprite
//just draw it up!!!!
for(Sprite dropOfKoffee : superStrongKoffee){
System.out.println("Fuck OFFF!!!!");
dropOfKoffee.draw(this.batch);
}
}
}else{
for(MapObject wtfIsThisObject : layer.getObjects()){
renderObject(wtfIsThisObject);
}
}
}
endRender();
}
示例8: createCoins
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
public static void createCoins(Map map, MapLayer layer, Box2DWorld world) {
Matrix4 transformMat4 = getTransformationMatrix(map);
Vector3 coinPos = new Vector3();
for(MapObject object : layer.getObjects()) {
if(object instanceof RectangleMapObject) {
RectangleMapObject rectangleObj = (RectangleMapObject)object;
// Get coin position from map object and transform it by transformation matrix
coinPos.set(rectangleObj.getRectangle().getX() + rectangleObj.getRectangle().width / 2,
rectangleObj.getRectangle().getY() + rectangleObj.getRectangle().height / 2, 0);
coinPos.mul(transformMat4);
// Create new Coin
Coin newCoin = new Coin(coinPos.x, coinPos.y, world);
// Add Coin entity to EntityManager
map.getEntMan().addCoin(newCoin);
}
}
}
示例9: getPlayerPosition
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
public static Vector2 getPlayerPosition(Map map, MapLayer layer) {
Vector2 playerPos = new Vector2(0,0);
for(MapObject object : layer.getObjects()) {
if(object instanceof EllipseMapObject) {
EllipseMapObject mapObject = (EllipseMapObject)object;
Vector3 tempVec3 = new Vector3();
tempVec3.set(mapObject.getEllipse().x + mapObject.getEllipse().width / 2,
mapObject.getEllipse().y + mapObject.getEllipse().height / 2, 0);
tempVec3.mul(getTransformationMatrix(map));
playerPos.set(tempVec3.x, tempVec3.y);
}
}
return playerPos;
}
示例10: generateEnemies
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private Array<Goomba> generateEnemies() {
Array<Goomba> goombas = new Array<Goomba>();
MapLayer layer = map.getLayers().get("objects");
MapObjects objects = layer.getObjects();
Iterator<MapObject> objectIt = objects.iterator();
while(objectIt.hasNext()) {
MapObject obj = objectIt.next();
String type = (String) obj.getProperties().get("type");
if(type != null) {
float x = (Float) obj.getProperties().get("x");
float y = (Float) obj.getProperties().get("y");
if(type.equals("goomba")) {
Goomba goomba = new Goomba(this, x * (1/16f), y* (1/16f));
goombas.add(goomba);
stage.addActor(goomba);
}
}
}
return goombas;
}
示例11: itemsInBrick
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
/**
* Check if there are items in a brick, if there are they are added to the brick.
* @param brick
* @param x
* @param y
*/
private void itemsInBrick(Brick brick, int x, int y) {
MapLayer layer = map.getLayers().get("hidden_items");
MapObjects objects = layer.getObjects();
for(MapObject obj : objects) {
int obj_x = (int) ((Float) obj.getProperties().get("x") * (1/16f));
int obj_y = (int) ((Float) obj.getProperties().get("y") * (1/16f));
if(obj_x == x && obj_y == y) {
String type = (String) obj.getProperties().get("type");
Actor item = null;
if(type.equals("super_mushroom")) {
item = new Super(this, x, y, 4f);
mushrooms.add((Mushroom) item);
}
stage.addActor(item);
brick.addItem(item);
}
}
}
示例12: loadUi
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private void loadUi(MapLayer layer, TextureAtlas atlas) {
MapObjects objects = layer.getObjects();
Array<String> added = new Array<String>();
for (MapObject o : objects) {
MapProperties properties = o.getProperties();
Actor ui_actor = getUiActor(added, o, properties, objects, atlas);
if (ui_actor != null)
uiground.addActor(ui_actor);
}
}
示例13: buildBodiesFromLayer
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
/**
* Erzeugt aus einem ObjectLayer Box2D Körper.
*
* @param layer die Ebene
* @param world die Box2D Welt
*/
public static void buildBodiesFromLayer(MapLayer layer, World world)
{
for(MapObject tileObject : layer.getObjects())
{
if (
tileObject instanceof TextureMapObject ||
tileObject instanceof CircleMapObject ||
tileObject instanceof EllipseMapObject)
continue;
Shape shape = createShape(tileObject, TYPE_COLLISION);
if (shape == null)
continue;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.StaticBody;
Body body = world.createBody(bodyDef);
FixtureDef fixture = new FixtureDef();
fixture.shape = shape;
fixture.filter.categoryBits = Physics.CATEGORY_WORLD;
fixture.filter.maskBits = Physics.MASK_WORLD;
body.createFixture(fixture);
shape.dispose();
}
}
示例14: loadObjects
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
protected MapController loadObjects(){
for(MapLayer layer : map.getLayers()){
final String name = layer.getName();
final GameEntityType currenType = getTypeByLayer(name);
for(MapObject object : layer.getObjects()) {
GameEntity gameEntity = generateEntityByObject(object, currenType);
}
}
return this;
}
示例15: getCollision
import com.badlogic.gdx.maps.MapLayer; //導入方法依賴的package包/類
private boolean getCollision(TiledMap map, int x, int y) {
boolean value = true;
boolean npc = false;
for (MapLayer layer : map.getLayers()) {
for (MapObject o : layer.getObjects()) {
MapProperties p = o.getProperties();
if (p.get(Tmx.TYPE) != null && p.get(Tmx.TYPE).equals(Tmx.NPC)) {
float oX = (Float)p.get(Tmx.X) + GameConfig.CELL_SCALE / 2f;
float oY = (Float)p.get(Tmx.Y) + GameConfig.CELL_SCALE / 2f;
// Normalize spawn position
oX = (int)Math.floor(oX / GameConfig.CELL_SCALE);
oY = (int)Math.floor(oY / GameConfig.CELL_SCALE);
if (oX == x && oY == y) {
value = true;
npc = true;
}
}
}
if (layer instanceof TiledMapTileLayer) {
TiledMapTileLayer tiledLayer = (TiledMapTileLayer) layer;
TiledMapTileLayer.Cell cell = tiledLayer.getCell(x, y);
if (cell != null && cell.getTile() != null) {
MapProperties properties = cell.getTile().getProperties();
boolean collision = Boolean.valueOf(properties.get(Tmx.COLLISION, "true", String.class));
if (!collision && !npc) {
value = false;
}
}
}
}
return value;
}