本文整理汇总了Java中com.badlogic.gdx.maps.MapProperties.put方法的典型用法代码示例。如果您正苦于以下问题:Java MapProperties.put方法的具体用法?Java MapProperties.put怎么用?Java MapProperties.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.maps.MapProperties
的用法示例。
在下文中一共展示了MapProperties.put方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadProperties
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
private void loadProperties (MapProperties properties, Element element) {
if (element.getName().equals("Properties")) {
for (Element property : element.getChildrenByName("Property")) {
String key = property.getAttribute("Key", null);
String type = property.getAttribute("Type", null);
String value = property.getText();
if (type.equals("Int32")) {
properties.put(key, Integer.parseInt(value));
} else if (type.equals("String")) {
properties.put(key, value);
} else if (type.equals("Boolean")) {
properties.put(key, value.equalsIgnoreCase("true"));
} else {
properties.put(key, value);
}
}
}
}
示例2: makeAction
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
private static boolean makeAction(MapProperties props, String propName) {
String propstr = (String) props.get(propName);
if (propstr == null) {
return false;
}
String[] acts = propstr.split(",");
ActionAction[] out = new ActionAction[acts.length];
for (int i = 0; i < acts.length; i++) {
String pp = acts[i];
char location = pp.charAt(0);
int colon = pp.indexOf(':');
if (location != 'r' && location != 'l' || colon == -1) {
throw new RuntimeException("Bad action string: " + pp);
}
out[i] = new ActionAction(location == 'r', pp.substring(1, colon),
MapAction.valueOf(pp.substring(colon + 1)));
}
props.put(propName, out);
return true;
}
示例3: TiledEntityDefinition
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
public TiledEntityDefinition(String name, String type, int layer, BodyDef bodyDef,
MapObject bodySkeleton, MapProperties properties,
TextureRegion textureRegion) {
super(name, type, bodyDef);
this.layer = layer;
this.properties = properties;
this.bodySkeleton = bodySkeleton;
fixtureDef = TiledUtils.getFixtureDefFromBodySkeleton(bodySkeleton);
String textureKey = properties.get("texture").toString();
if (StringUtils.isEmpty(textureKey)) {
this.textureRegion = textureRegion;
} else {
this.textureRegion = AssetManager.getInstance().getTextureRegion(textureKey);
}
// This is kind of hacky...
Iterator<String> keys = properties.getKeys();
while (keys.hasNext()) {
String key = keys.next();
Object value = properties.get(key);
if (value.toString().toLowerCase().equals("null")) {
properties.put(key, null);
}
}
}
示例4: validateAndProcess
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
public static void validateAndProcess(PropertyConfiguration configuration, String type,
MapProperties mapProperties) {
PropertyConfiguration.Properties properties = configuration.getProperties(type);
if (properties == null) {
throw new InvalidConfigException(type + ": Properties not set for type");
}
// Check that all required properties are set.
for (String requiredProperty : properties.getRequiredProperties()) {
if (!mapProperties.containsKey(requiredProperty)) {
throw new InvalidConfigException(type + ": Required property '" + requiredProperty + "' missing");
}
}
// Check that all properties are valid.
Iterator<String> propertiesIter = mapProperties.getKeys();
while (propertiesIter.hasNext()) {
String property = propertiesIter.next();
if (property.equals("gid") || property.equals("texture")) {
continue;
}
if (!properties.propertyExists(property)) {
throw new InvalidConfigException(type + ": Property '" + property + "' is not valid");
}
}
// Fill in missing optional properties with defaults.
for (String optionalProperty : properties.getOptionalProperties()) {
String defaultVal = properties.getPropertyDefaultVal(optionalProperty);
if (!mapProperties.containsKey(optionalProperty)) {
mapProperties.put(optionalProperty, defaultVal);
}
}
}
示例5: addObject
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
MockObjectLayerBuilder addObject(float x, float y, float size, Object type, boolean collision) {
MapObject object = new MapObject();
MapProperties properties = object.getProperties();
properties.put(Constants.X, x);
properties.put(Constants.Y, y);
properties.put(Constants.WIDTH, size);
properties.put(Constants.HEIGHT, size);
properties.put(Constants.TYPE, type);
properties.put(Constants.COLLISION, collision);
objects.add(object);
return this;
}
示例6: MockTiledMapBuilder
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
public MockTiledMapBuilder(int xTiles, int yTiles, int tileSize) {
map = mock(TiledMap.class);
layers = new MapLayers();
MapProperties properties = new MapProperties();
properties.put(Constants.WIDTH, xTiles);
properties.put(Constants.HEIGHT, yTiles);
when(map.getProperties()).thenReturn(properties);
this.size = tileSize;
}
示例7: loadProperties
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
protected void loadProperties (MapProperties properties, Element element) {
if (element == null) return;
if (element.getName().equals("properties")) {
for (Element property : element.getChildrenByName("property")) {
String name = property.getAttribute("name", null);
String value = property.getAttribute("value", null);
if (value == null) {
value = property.getText();
}
properties.put(name, value);
}
}
}
示例8: copyLayerProperties
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
public static void copyLayerProperties(TiledMapTileLayer from, TiledMapTileLayer to) {
MapProperties fromP = from.getProperties();
MapProperties toP = to.getProperties();
Iterator<String> it = fromP.getKeys();
while (it.hasNext()) {
String key = it.next();
toP.put(key, fromP.get(key));
}
}
示例9: setBoolDefault
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
private static void setBoolDefault(MapProperties p, String name, boolean def) {
String str = (String) p.get(name);
if (str != null) {
def = Boolean.parseBoolean(str);
}
p.put(name, def);
}
示例10: loadMap
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
protected TiledMap loadMap(Element root, FileHandle tmxFile, AtlasResolver resolver) {
TiledMap map = new TiledMap();
String mapOrientation = root.getAttribute("orientation", null);
int mapWidth = root.getIntAttribute("width", 0);
int mapHeight = root.getIntAttribute("height", 0);
int tileWidth = root.getIntAttribute("tilewidth", 0);
int tileHeight = root.getIntAttribute("tileheight", 0);
String mapBackgroundColor = root.getAttribute("backgroundcolor", null);
MapProperties mapProperties = map.getProperties();
if (mapOrientation != null) {
mapProperties.put("orientation", mapOrientation);
}
mapProperties.put("width", mapWidth);
mapProperties.put("height", mapHeight);
mapProperties.put("tilewidth", tileWidth);
mapProperties.put("tileheight", tileHeight);
if (mapBackgroundColor != null) {
mapProperties.put("backgroundcolor", mapBackgroundColor);
}
mapTileWidth = tileWidth;
mapTileHeight = tileHeight;
mapWidthInPixels = mapWidth * tileWidth;
mapHeightInPixels = mapHeight * tileHeight;
if (mapOrientation != null) {
if ("staggered".equals(mapOrientation)) {
if (mapHeight > 1) {
mapWidthInPixels += tileWidth / 2;
mapHeightInPixels = mapHeightInPixels / 2 + tileHeight / 2;
}
}
}
for (int i = 0, j = root.getChildCount(); i < j; i++) {
Element element = root.getChild(i);
String elementName = element.getName();
if (elementName.equals("properties")) {
loadProperties(map.getProperties(), element);
String types_path = "kyperbox_types.xml";
if (types == null) {
types = new TiledObjectTypes(types_path);
templates = new TiledTemplates(types, "");
}
} else if (elementName.equals("tileset")) {
loadTileset(map, element, tmxFile, resolver);
} else if (elementName.equals("layer")) {
loadTileLayer(map, map.getLayers(), element);
} else if (elementName.equals("objectgroup")) {
loadObjectGroup(map, map.getLayers(), element);
}
}
return map;
}
示例11: loadMap
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
protected TiledMap loadMap (Element root, FileHandle tmxFile, AtlasResolver resolver) {
TiledMap map = new TiledMap();
String mapOrientation = root.getAttribute("orientation", null);
int mapWidth = root.getIntAttribute("width", 0);
int mapHeight = root.getIntAttribute("height", 0);
int tileWidth = root.getIntAttribute("tilewidth", 0);
int tileHeight = root.getIntAttribute("tileheight", 0);
String mapBackgroundColor = root.getAttribute("backgroundcolor", null);
MapProperties mapProperties = map.getProperties();
if (mapOrientation != null) {
mapProperties.put("orientation", mapOrientation);
}
mapProperties.put("width", mapWidth);
mapProperties.put("height", mapHeight);
mapProperties.put("tilewidth", tileWidth);
mapProperties.put("tileheight", tileHeight);
if (mapBackgroundColor != null) {
mapProperties.put("backgroundcolor", mapBackgroundColor);
}
mapTileWidth = tileWidth;
mapTileHeight = tileHeight;
mapWidthInPixels = mapWidth * tileWidth;
mapHeightInPixels = mapHeight * tileHeight;
for (int i = 0, j = root.getChildCount(); i < j; i++) {
Element element = root.getChild(i);
String elementName = element.getName();
if (elementName.equals("properties")) {
loadProperties(map.getProperties(), element);
} else if (elementName.equals("tileset")) {
loadTileset(map, element, tmxFile, resolver);
} else if (elementName.equals("layer")) {
loadTileLayer(map, element);
} else if (elementName.equals("objectgroup")) {
loadObjectGroup(map, element);
}
}
return map;
}
示例12: activate
import com.badlogic.gdx.maps.MapProperties; //导入方法依赖的package包/类
/**
* Handles players interaction with other objects, excluding physics
*
* @param tileTouch
* - Which tile is to be activated
* @param mapa
* - The current level's map
*/
public void activate(Vector2 tileTouch, TiledMap map) {
// Look for object at touch position
Vector2 screenTouch = tileTouch.cpy().scl(TILE_WIDTH);
Gdx.app.log(TAG, String.format(" + Activating (%f, %f)", screenTouch.x,
screenTouch.y));
MainScreen screen = (MainScreen) ((MySidekick) Gdx.app
.getApplicationListener()).getScreen();
// Look for objects to interact with
for (MapObject o : map.getLayers().get(C.ObjectLayer).getObjects()) {
MapProperties props = o.getProperties();
String type = (String) props.get("type");
if (type == null)
continue; // Can't determine type of object
if ((Integer) props.get("x") == screenTouch.x
&& (Integer) props.get("y") == screenTouch.y
&& o.isVisible()) {
if (type.equals("npc")) { // NPC
Gdx.app.log(TAG, "Activating NPC");
// Activate NPC
String npcName = o.getName();
// check if user has key for npc
boolean hasKey = props.get("hasKey", false, Boolean.class);
if (hasKey) {
screen.setMsgBoxText(npcName
+ ": Happy travels comrade.");
if ((Boolean) (props.get("used")) == false) {
// TODO: activate a pillar
Gdx.app.log(
TAG,
"Activating pillar "
+ props.get("pillarNum"));
mPillarCount += 1;
}
props.put("used", true);
} else {
((MainScreen) (((MySidekick) Gdx.app
.getApplicationListener()).getScreen()))
.setMsgBoxText(npcName
+ " doesn't trust you, yet.");
}
}
}
}
if (mPillarCount >= 5) {
MapObject portal = map.getLayers().get(C.ObjectLayer).getObjects()
.get("portal");
if (portal != null) {
Gdx.app.log(TAG, "Unlocking portal");
portal.setVisible(true);
// Make entity for collision purposes
TiledMapTileLayer tileLayer = ((TiledMapTileLayer) screen.map
.getLayers().get(C.TileLayer));
Vector2 center = new Vector2(tileLayer.getWidth() / 2,
tileLayer.getHeight() / 2);
new Portal(screen.map.getTileSets().getTile(Portal.PORTAL_ID)
.getTextureRegion(), center.x, center.y,
MySidekick.getWorld());
}
}
}