mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 00:22:43 +08:00
+2
-1
@@ -569,7 +569,8 @@ if (CC_DEBUG) {
|
||||
"7217": "cocos2d: TMXFomat: Unsupported orientation: %s", //parseXMLFile
|
||||
"7218": "cc.TMXMapInfo.parseXMLFile(): unsupported compression method", //_parseLayer
|
||||
"7219": "cc.TMXMapInfo.parseXMLFile(): Only base64 and/or gzip/zlib maps are supported", //_parseLayer
|
||||
"7220": "TMX Parser: please load the xml resource first: %s", // parseXMLFile
|
||||
"7220": "cc.TMXMapInfo.parseXMLFile(): please load the xml resource first: %s", // parseXMLFile
|
||||
"7221": "cc.TMXMapInfo.parseXMLFile(): Texture '%s' not found.",
|
||||
//Wrapper: 7300
|
||||
"7300": "The new selected must be number", //CheckBox.selected
|
||||
"7301": "The new bake must be boolean", //layer
|
||||
|
||||
@@ -209,13 +209,14 @@ _ccsg.TMXLayer = _ccsg.Node.extend(/** @lends _ccsg.TMXLayer# */{
|
||||
this._texGrids = [];
|
||||
for (i = 0; i < len; ++i) {
|
||||
tileset = tilesets[i];
|
||||
tex = cc.textureCache.addImage(tileset.sourceImage, function (tex) {
|
||||
tex = tileset.sourceImage;
|
||||
if (tex) {
|
||||
tex.setAliasTexParameters();
|
||||
});
|
||||
this._textures[i] = tex;
|
||||
this._fillTextureGrids(tileset, i);
|
||||
if (tileset === tilesetInfo) {
|
||||
this._texture = tex;
|
||||
this._textures[i] = tex;
|
||||
this._fillTextureGrids(tileset, i);
|
||||
if (tileset === tilesetInfo) {
|
||||
this._texture = tex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,8 +147,10 @@ _ccsg.TMXObjectImage = _ccsg.Sprite.extend(/** @lends cc.TMXObjectImage# */{
|
||||
this.setVisible(this._container.objectVisible);
|
||||
|
||||
// init the image
|
||||
var texture = cc.textureCache.addImage(cc.path._normalize(tileset.sourceImage));
|
||||
this._initWithTileset(texture, useTileset);
|
||||
var texture = tileset.sourceImage;
|
||||
if (texture) {
|
||||
this._initWithTileset(texture, useTileset);
|
||||
}
|
||||
|
||||
// init the position & anchor point with map info
|
||||
this._initPosWithMapInfo(mapInfo);
|
||||
|
||||
@@ -114,19 +114,11 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{
|
||||
/**
|
||||
* Creates a TMX Tiled Map with a TMX file or content string. <br/>
|
||||
* Constructor of _ccsg.TMXTiledMap
|
||||
* @param {String} tmxFile tmxFile fileName or content string
|
||||
* @param {String} resourcePath If tmxFile is a file name ,it is not required.If tmxFile is content string ,it is must required.
|
||||
*/
|
||||
ctor:function(tmxFile,resourcePath){
|
||||
ctor:function(){
|
||||
_ccsg.Node.prototype.ctor.call(this);
|
||||
this._mapSize = cc.size(0, 0);
|
||||
this._tileSize = cc.size(0, 0);
|
||||
|
||||
if(resourcePath !== undefined){
|
||||
this.initWithXML(tmxFile,resourcePath);
|
||||
}else if(tmxFile !== undefined){
|
||||
this.initWithTMXFile(tmxFile);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -235,43 +227,18 @@ _ccsg.TMXTiledMap = _ccsg.Node.extend(/** @lends _ccsg.TMXTiledMap# */{
|
||||
this.properties = Var;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes the instance of _ccsg.TMXTiledMap with tmxFile
|
||||
* @param {String} tmxFile
|
||||
* @return {Boolean} Whether the initialization was successful.
|
||||
* @example
|
||||
* //example
|
||||
* var map = new _ccsg.TMXTiledMap()
|
||||
* map.initWithTMXFile("hello.tmx");
|
||||
*/
|
||||
initWithTMXFile:function (tmxFile) {
|
||||
if(!tmxFile || tmxFile.length === 0) {
|
||||
return false;
|
||||
}
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
var mapInfo = new cc.TMXMapInfo(tmxFile);
|
||||
if (!mapInfo)
|
||||
return false;
|
||||
|
||||
var locTilesets = mapInfo.getTilesets();
|
||||
if(!locTilesets || locTilesets.length === 0)
|
||||
cc.logID(7212);
|
||||
this._buildWithMapInfo(mapInfo);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes the instance of _ccsg.TMXTiledMap with tmxString
|
||||
* @param {String} tmxString
|
||||
* @param {String} resourcePath
|
||||
* @param {Object} textures
|
||||
* @return {Boolean} Whether the initialization was successful.
|
||||
*/
|
||||
initWithXML:function(tmxString, resourcePath){
|
||||
initWithXML: function(tmxString, resourcePath, textures){
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
|
||||
var mapInfo = new cc.TMXMapInfo(tmxString, resourcePath);
|
||||
var mapInfo = new cc.TMXMapInfo(tmxString, resourcePath, textures);
|
||||
var locTilesets = mapInfo.getTilesets();
|
||||
if(!locTilesets || locTilesets.length === 0)
|
||||
cc.logID(7213);
|
||||
|
||||
@@ -147,7 +147,7 @@ cc.TMXObjectGroupInfo = cc._Class.extend(/** @lends cc.TMXObjectGroupInfo# */{
|
||||
* @property {number} firstGid - First grid
|
||||
* @property {number} spacing - Spacing
|
||||
* @property {number} margin - Margin
|
||||
* @property {string} sourceImage - Filename containing the tiles (should be sprite sheet / texture atlas)
|
||||
* @property {null} sourceImage - Texture containing the tiles (should be sprite sheet / texture atlas)
|
||||
* @property {cc.Size} imageSize - Size in pixels of the image
|
||||
*/
|
||||
cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{
|
||||
@@ -161,8 +161,8 @@ cc.TMXTilesetInfo = cc._Class.extend(/** @lends cc.TMXTilesetInfo# */{
|
||||
this.spacing = 0;
|
||||
// Margin
|
||||
this.margin = 0;
|
||||
// Filename containing the tiles (should be sprite sheet / texture atlas)
|
||||
this.sourceImage = "";
|
||||
// Texture containing the tiles (should be sprite sheet / texture atlas)
|
||||
this.sourceImage = null;
|
||||
// Size in pixels of the image
|
||||
this.imageSize = cc.size(0, 0);
|
||||
|
||||
@@ -222,7 +222,6 @@ function getPropertyList (node) {
|
||||
* @property {Number} parentGID - Parent GID.
|
||||
* @property {Object} layerAttrs - Layer attributes.
|
||||
* @property {Boolean} storingCharacters - Is reading storing characters stream.
|
||||
* @property {String} tmxFileName - TMX file name.
|
||||
* @property {String} currentString - Current string stored from characters stream.
|
||||
* @property {Number} mapWidth - Width of the map
|
||||
* @property {Number} mapHeight - Height of the map
|
||||
@@ -249,7 +248,6 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
parentGID:null,
|
||||
layerAttrs:0,
|
||||
storingCharacters:false,
|
||||
tmxFileName:null,
|
||||
currentString:null,
|
||||
|
||||
_objectGroups:null,
|
||||
@@ -260,7 +258,10 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
_tilesets:null,
|
||||
// tile properties
|
||||
_tileProperties:null,
|
||||
_resources:"",
|
||||
_resources: "", // used to load relative tsx
|
||||
|
||||
// map of textures indexed by name
|
||||
_textures: null,
|
||||
|
||||
// hex map values
|
||||
_staggerAxis: null,
|
||||
@@ -270,10 +271,11 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
/**
|
||||
* Creates a TMX Format with a tmx file or content string <br/>
|
||||
* Constructor of cc.TMXMapInfo
|
||||
* @param {String} tmxFile fileName or content string
|
||||
* @param {String} resourcePath If tmxFile is a file name ,it is not required.If tmxFile is content string ,it is must required.
|
||||
* @param {String} tmxFile content string
|
||||
* @param {String} resourcePath
|
||||
* @param {Object} textures
|
||||
*/
|
||||
ctor:function (tmxFile, resourcePath) {
|
||||
ctor: function (tmxFile, resourcePath, textures) {
|
||||
cc.SAXParser.prototype.ctor.apply(this);
|
||||
this._mapSize = cc.size(0, 0);
|
||||
this._tileSize = cc.size(0, 0);
|
||||
@@ -284,11 +286,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
this.properties = [];
|
||||
this._tileProperties = {};
|
||||
|
||||
if (resourcePath !== undefined) {
|
||||
this.initWithXML(tmxFile,resourcePath);
|
||||
} else if(tmxFile !== undefined){
|
||||
this.initWithTMXFile(tmxFile);
|
||||
}
|
||||
this.initWithXML(tmxFile, resourcePath, textures);
|
||||
},
|
||||
/**
|
||||
* Gets Map orientation.
|
||||
@@ -548,24 +546,33 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
this.properties = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes a TMX format with a tmx file
|
||||
* @param {String} tmxFile
|
||||
* @return {Element}
|
||||
*/
|
||||
initWithTMXFile:function (tmxFile) {
|
||||
this._internalInit(tmxFile, null);
|
||||
return this.parseXMLFile(tmxFile);
|
||||
},
|
||||
|
||||
/**
|
||||
* initializes a TMX format with an XML string and a TMX resource path
|
||||
* @param {String} tmxString
|
||||
* @param {String} resourcePath
|
||||
* @param {Object} textures
|
||||
* @return {Boolean}
|
||||
*/
|
||||
initWithXML:function (tmxString, resourcePath) {
|
||||
this._internalInit(null, resourcePath);
|
||||
initWithXML:function (tmxString, resourcePath, textures) {
|
||||
|
||||
this._tilesets.length = 0;
|
||||
this._layers.length = 0;
|
||||
|
||||
if (resourcePath)
|
||||
this._resources = resourcePath;
|
||||
this._textures = textures;
|
||||
|
||||
this._objectGroups.length = 0;
|
||||
this._allChildren.length = 0;
|
||||
this.properties.length = 0;
|
||||
this._tileProperties.length = 0;
|
||||
|
||||
// tmp vars
|
||||
this.currentString = "";
|
||||
this.storingCharacters = false;
|
||||
this.layerAttrs = cc.TMXLayerInfo.ATTRIB_NONE;
|
||||
this.parentElement = cc.TiledMap.NONE;
|
||||
|
||||
return this.parseXMLString(tmxString);
|
||||
},
|
||||
|
||||
@@ -680,14 +687,9 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
|
||||
var image = selTileset.getElementsByTagName('image')[0];
|
||||
var imagename = image.getAttribute('source');
|
||||
var num = -1;
|
||||
if(this.tmxFileName)
|
||||
num = this.tmxFileName.lastIndexOf("/");
|
||||
if (num !== -1) {
|
||||
var dir = this.tmxFileName.substr(0, num + 1);
|
||||
tileset.sourceImage = dir + imagename;
|
||||
} else {
|
||||
tileset.sourceImage = this._resources + (this._resources ? "/" : "") + imagename;
|
||||
tileset.sourceImage = this._textures[imagename];
|
||||
if (!tileset.sourceImage) {
|
||||
cc.errorID(7221, imagename);
|
||||
}
|
||||
|
||||
this.setTilesets(tileset);
|
||||
@@ -991,42 +993,6 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
|
||||
*/
|
||||
setCurrentString:function (currentString) {
|
||||
this.currentString = currentString;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the tmxFileName
|
||||
* @return {String}
|
||||
*/
|
||||
getTMXFileName:function () {
|
||||
return this.tmxFileName;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the tmxFileName
|
||||
* @param {String} fileName
|
||||
*/
|
||||
setTMXFileName:function (fileName) {
|
||||
this.tmxFileName = fileName;
|
||||
},
|
||||
|
||||
_internalInit:function (tmxFileName, resourcePath) {
|
||||
this._tilesets.length = 0;
|
||||
this._layers.length = 0;
|
||||
|
||||
this.tmxFileName = tmxFileName;
|
||||
if (resourcePath)
|
||||
this._resources = resourcePath;
|
||||
|
||||
this._objectGroups.length = 0;
|
||||
this._allChildren.length = 0;
|
||||
this.properties.length = 0;
|
||||
this._tileProperties.length = 0;
|
||||
|
||||
// tmp vars
|
||||
this.currentString = "";
|
||||
this.storingCharacters = false;
|
||||
this.layerAttrs = cc.TMXLayerInfo.ATTRIB_NONE;
|
||||
this.parentElement = cc.TiledMap.NONE;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1047,18 +1013,6 @@ _p.tileHeight;
|
||||
cc.defineGetterSetter(_p, "tileHeight", _p._getTileHeight, _p._setTileHeight);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a TMX Format with a tmx file or content string
|
||||
* @deprecated since v3.0 please use new cc.TMXMapInfo(tmxFile, resourcePath) instead.
|
||||
* @param {String} tmxFile fileName or content string
|
||||
* @param {String} resourcePath If tmxFile is a file name ,it is not required.If tmxFile is content string ,it is must required.
|
||||
* @return {cc.TMXMapInfo}
|
||||
*/
|
||||
cc.TMXMapInfo.create = function (tmxFile, resourcePath) {
|
||||
return new cc.TMXMapInfo(tmxFile, resourcePath);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type Number
|
||||
|
||||
@@ -853,7 +853,14 @@ var TiledMap = cc.Class({
|
||||
resPath = resPath.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
var ret = sgNode.initWithXML(file.tmxXmlStr, resPath);
|
||||
var texValues = file.textures;
|
||||
var texKeys = file.textureNames;
|
||||
var textures = {};
|
||||
for (let i = 0; i < texValues.length; ++i) {
|
||||
textures[texKeys[i]] = texValues[i];
|
||||
}
|
||||
|
||||
var ret = sgNode.initWithXML(file.tmxXmlStr, resPath, textures);
|
||||
if (ret) {
|
||||
// Asset is changed, the layers are recreated.
|
||||
// The layers of pre asset should be cleaned.
|
||||
@@ -864,11 +871,11 @@ var TiledMap = cc.Class({
|
||||
// tmx file is cleared
|
||||
// 1. hide the tmx layers & groups in _sgNode
|
||||
var layers = sgNode.allLayers();
|
||||
for (var i = 0, n = layers.length; i < n; i++) {
|
||||
for (let i = 0, n = layers.length; i < n; i++) {
|
||||
sgNode.removeChild(layers[i]);
|
||||
}
|
||||
var groups = sgNode.getObjectGroups();
|
||||
for (i = 0, n = groups.length; i < n; i++) {
|
||||
for (let i = 0, n = groups.length; i < n; i++) {
|
||||
sgNode.removeChild(groups[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,23 +34,20 @@ var TiledMapAsset = cc.Class({
|
||||
extends: cc.Asset,
|
||||
|
||||
properties: {
|
||||
tmxXmlStr: {
|
||||
default: ''
|
||||
},
|
||||
tmxXmlStr: '',
|
||||
tmxFolderPath: '',
|
||||
|
||||
tmxFolderPath : {
|
||||
default: ''
|
||||
},
|
||||
/**
|
||||
* @property {Texture2D[]} textures
|
||||
*/
|
||||
textures: [cc.Texture2D],
|
||||
|
||||
textures: {
|
||||
default: [],
|
||||
type: [cc.Texture2D]
|
||||
},
|
||||
/**
|
||||
* @property {String[]} textureNames
|
||||
*/
|
||||
textureNames: [cc.String],
|
||||
|
||||
tsxFiles: {
|
||||
default: [],
|
||||
url: [cc.RawAsset]
|
||||
}
|
||||
tsxFiles: [cc.RawAsset]
|
||||
},
|
||||
|
||||
statics: {
|
||||
|
||||
@@ -65,7 +65,7 @@ class TiledMapMeta extends CustomAssetMeta {
|
||||
this._tsxFiles = [];
|
||||
}
|
||||
|
||||
static version () { return '1.0.4'; }
|
||||
static version () { return '2.0.0'; }
|
||||
static defaultType() { return 'tiled-map'; }
|
||||
|
||||
import (fspath, cb) {
|
||||
@@ -99,6 +99,7 @@ class TiledMapMeta extends CustomAssetMeta {
|
||||
var uuid = db.fspathToUuid(p);
|
||||
return uuid ? Editor.serialize.asAsset(uuid) : null;
|
||||
});
|
||||
asset.textureNames = this._textures.map(p => Path.basename(p));
|
||||
asset.tsxFiles = this._tsxFiles.map(p => db.fspathToUrl(p));
|
||||
db.saveAssetToLibrary(this.uuid, asset);
|
||||
cb();
|
||||
|
||||
Reference in New Issue
Block a user