Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-gc0630

This commit is contained in:
Dhilan007 2014-06-30 13:41:55 +08:00
commit 2a9e10be2c
28 changed files with 3624 additions and 373 deletions

View File

@ -1,4 +1,5 @@
cocos2d-x-3.2 ???
[NEW] FastTMXTiledMap: added fast tmx, which is much more faster for static tiled map
[NEW] GLProgramState: can use uniform location to get/set uniform values
[NEW] HttpClient: added sendImmediate()
[NEW] Label: support setting line height and additional kerning of label that not using system font
@ -8,14 +9,22 @@ cocos2d-x-3.2 ???
[NEW] Node: added getName(), setName(), getChildByName(), enumerateChildren()
and addChild(Node* node, int localZOrder, const std::string &name)
[NEW] Node: physical body supports rotation
[NEW] Sprite3D: support c3b binary format
[NEW] utils: added findChildren() to find all children by name
[NEW] Value: added operator == !=
[FIX] Armature: blend func has no effect
[FIX] Armature: crashed when remove armature in frame event
[FIX] Animation3D: doesn't load original pose, which leads to wrong effect if not playing animation
[FIX] Animation3D: animation for unskined bones lost
[FIX] FileUtils: getStringFromFile may return a unterminated string
[FIX] Lua-binding: Sequence:create will cause drop-dead issue
[FIX] Lua-binding: lua-tests cant be loaded on 64 bits iOS devices and Linux
[FIX] Node: Node::setScale(float) may not work properly
[FIX] Physics integration: child node can move with its father
[FIX] Physics integration: support scale
[FIX] Sprite3D: 20% performce improved, simplify shader, use VAO and batch draw
[FIX] Studio support: NodeReader may cause crash
[FIX] UIButton: doesn't support TTF font
[FIX] UIButton: `getTitleColor()` doesn't equal to the value set by `setTitleColor()`

854
cocos/2d/CCFastTMXLayer.cpp Normal file
View File

@ -0,0 +1,854 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
Copyright (c) 2011 HKASoftware
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/*
Original rewrite of TMXLayer was based on HKTMXTiledMap by HKASoftware http://hkasoftware.com
Further info: http://www.cocos2d-iphone.org/forums/topic/hktmxtiledmap/
It was rewritten again, and only a small part of the original HK ideas/code remains in this implementation
*/
#include "CCFastTMXLayer.h"
#include "CCTMXXMLParser.h"
#include "CCFastTMXTiledMap.h"
#include "2d/CCSprite.h"
#include "renderer/CCTextureCache.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/CCGLProgram.h"
#include "base/CCDirector.h"
#include "base/CCConfiguration.h"
#include "renderer/CCRenderer.h"
#include "deprecated/CCString.h"
#include "renderer/CCGLProgramStateCache.h"
#include <algorithm>
NS_CC_BEGIN
const int FastTMXLayer::FAST_TMX_ORIENTATION_ORTHO = 0;
const int FastTMXLayer::FAST_TMX_ORIENTATION_HEX = 1;
const int FastTMXLayer::FAST_TMX_ORIENTATION_ISO = 2;
// FastTMXLayer - init & alloc & dealloc
FastTMXLayer * FastTMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
FastTMXLayer *ret = new FastTMXLayer();
if (ret->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
ret->autorelease();
return ret;
}
return nullptr;
}
bool FastTMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
if( tilesetInfo )
{
_texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage);
_texture->retain();
}
// layerInfo
_layerName = layerInfo->_name;
_layerSize = layerInfo->_layerSize;
_tiles = layerInfo->_tiles;
_quadsDirty = true;
setOpacity( layerInfo->_opacity );
setProperties(layerInfo->getProperties());
// tilesetInfo
_tileSet = tilesetInfo;
CC_SAFE_RETAIN(_tileSet);
// mapInfo
_mapTileSize = mapInfo->getTileSize();
_layerOrientation = mapInfo->getOrientation();
// offset (after layer orientation is set);
Vec2 offset = this->calculateLayerOffset(layerInfo->_offset);
this->setPosition(CC_POINT_PIXELS_TO_POINTS(offset));
this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(Size(_layerSize.width * _mapTileSize.width, _layerSize.height * _mapTileSize.height)));
this->tileToNodeTransform();
// shader, and other stuff
setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
_useAutomaticVertexZ = false;
_vertexZvalue = 0;
return true;
}
FastTMXLayer::FastTMXLayer()
: _layerName("")
, _layerSize(Size::ZERO)
, _mapTileSize(Size::ZERO)
, _tiles(nullptr)
, _tileSet(nullptr)
, _layerOrientation(FAST_TMX_ORIENTATION_ORTHO)
,_texture(nullptr)
, _vertexZvalue(0)
, _useAutomaticVertexZ(false)
, _dirty(true)
, _quadsDirty(true)
{
_buffersVBO[0] = _buffersVBO[1] = 0;
}
FastTMXLayer::~FastTMXLayer()
{
CC_SAFE_RELEASE(_tileSet);
CC_SAFE_RELEASE(_texture);
CC_SAFE_DELETE_ARRAY(_tiles);
if(glIsBuffer(_buffersVBO[0]))
{
glDeleteBuffers(1, &_buffersVBO[0]);
}
if(glIsBuffer(_buffersVBO[1]))
{
glDeleteBuffers(1, &_buffersVBO[1]);
}
}
void FastTMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags)
{
updateTotalQuads();
if( flags != 0 || _dirty || _quadsDirty )
{
Size s = Director::getInstance()->getWinSize();
auto rect = Rect(0, 0, s.width, s.height);
Mat4 inv = transform;
inv.inverse();
rect = RectApplyTransform(rect, inv);
updateTiles(rect);
updateIndexBuffer();
_dirty = false;
}
if(_renderCommands.size() < _indicesVertexZNumber.size())
{
_renderCommands.resize(_indicesVertexZNumber.size());
}
int index = 0;
for(const auto& iter : _indicesVertexZNumber)
{
auto& cmd = _renderCommands[index++];
cmd.init(iter.first);
cmd.func = CC_CALLBACK_0(FastTMXLayer::onDraw, this, _indicesVertexZOffsets[iter.first], iter.second);
renderer->addCommand(&cmd);
}
}
void FastTMXLayer::onDraw(int offset, int count)
{
GL::bindTexture2D(_texture->getName());
getGLProgramState()->apply(_modelViewTransform);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)0);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, colors));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid*)offsetof(V3F_C4B_T2F, texCoords));
glDrawElements(GL_TRIANGLES, (GLsizei)count * 6, GL_UNSIGNED_INT, (GLvoid*)(offset * 6 * sizeof(int)));
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, count * 4);
}
void FastTMXLayer::updateTiles(const Rect& culledRect)
{
Rect visibleTiles = culledRect;
Size mapTileSize = CC_SIZE_PIXELS_TO_POINTS(_mapTileSize);
Size tileSize = CC_SIZE_PIXELS_TO_POINTS(_tileSet->_tileSize);
Mat4 nodeToTileTransform = _tileToNodeTransform.getInversed();
//transform to tile
visibleTiles = RectApplyTransform(visibleTiles, nodeToTileTransform);
// tile coordinate is upside-down, so we need to make the tile coordinate use top-left for the start point.
visibleTiles.origin.y += 1;
// if x=0.7, width=9.5, we need to draw number 0~10 of tiles, and so is height.
visibleTiles.size.width = ceil(visibleTiles.origin.x + visibleTiles.size.width) - floor(visibleTiles.origin.x);
visibleTiles.size.height = ceil(visibleTiles.origin.y + visibleTiles.size.height) - floor(visibleTiles.origin.y);
visibleTiles.origin.x = floor(visibleTiles.origin.x);
visibleTiles.origin.y = floor(visibleTiles.origin.y);
// for the bigger tiles.
int tilesOverX = 0;
int tilesOverY = 0;
// for diagonal oriention tiles
float tileSizeMax = std::max(tileSize.width, tileSize.height);
if (_layerOrientation == FAST_TMX_ORIENTATION_ORTHO)
{
tilesOverX = ceil(tileSizeMax / mapTileSize.width) - 1;
tilesOverY = ceil(tileSizeMax / mapTileSize.height) - 1;
if (tilesOverX < 0) tilesOverX = 0;
if (tilesOverY < 0) tilesOverY = 0;
}
else if(_layerOrientation == FAST_TMX_ORIENTATION_ISO)
{
Rect overTileRect(0, 0, tileSizeMax - mapTileSize.width, tileSizeMax - mapTileSize.height);
if (overTileRect.size.width < 0) overTileRect.size.width = 0;
if (overTileRect.size.height < 0) overTileRect.size.height = 0;
overTileRect = RectApplyTransform(overTileRect, nodeToTileTransform);
tilesOverX = ceil(overTileRect.origin.x + overTileRect.size.width) - floor(overTileRect.origin.x);
tilesOverY = ceil(overTileRect.origin.y + overTileRect.size.height) - floor(overTileRect.origin.y);
}
else
{
//do nothing, do not support
CCASSERT(0, "TMX invalid value");
}
_indicesVertexZNumber.clear();
for(const auto& iter : _indicesVertexZOffsets)
{
_indicesVertexZNumber[iter.first] = iter.second;
}
int yBegin = std::max(0.f,visibleTiles.origin.y - tilesOverY);
int yEnd = std::min(_layerSize.height,visibleTiles.origin.y + visibleTiles.size.height + tilesOverY);
int xBegin = std::max(0.f,visibleTiles.origin.x - tilesOverX);
int xEnd = std::min(_layerSize.width,visibleTiles.origin.x + visibleTiles.size.width + tilesOverX);
for (int y = yBegin; y < yEnd; ++y)
{
for (int x = xBegin; x < xEnd; ++x)
{
int tileIndex = getTileIndexByPos(x, y);
if(_tiles[tileIndex] == 0) continue;
int vertexZ = getVertexZForPos(Vec2(x,y));
auto iter = _indicesVertexZNumber.find(vertexZ);
int offset = iter->second;
iter->second++;
//CC_ASSERT(_tileToQuadIndex.find(tileIndex) != _tileToQuadIndex.end() && _tileToQuadIndex[tileIndex] <= _totalQuads.size()-1);
int quadIndex = (int)_tileToQuadIndex[tileIndex];
_indices[6 * offset + 0] = quadIndex * 4 + 0;
_indices[6 * offset + 1] = quadIndex * 4 + 1;
_indices[6 * offset + 2] = quadIndex * 4 + 2;
_indices[6 * offset + 3] = quadIndex * 4 + 3;
_indices[6 * offset + 4] = quadIndex * 4 + 2;
_indices[6 * offset + 5] = quadIndex * 4 + 1;
} // for x
} // for y
for(const auto& iter : _indicesVertexZOffsets)
{
_indicesVertexZNumber[iter.first] -= iter.second;
if(_indicesVertexZNumber[iter.first] == 0)
{
_indicesVertexZNumber.erase(iter.first);
}
}
}
void FastTMXLayer::updateVertexBuffer()
{
GL::bindVAO(0);
if(!glIsBuffer(_buffersVBO[0]))
{
glGenBuffers(1, &_buffersVBO[0]);
}
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B_T2F_Quad) * _totalQuads.size(), (GLvoid*)&_totalQuads[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void FastTMXLayer::updateIndexBuffer()
{
if(!glIsBuffer(_buffersVBO[1]))
{
glGenBuffers(1, &_buffersVBO[1]);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * _indices.size(), &_indices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
// FastTMXLayer - setup Tiles
void FastTMXLayer::setupTiles()
{
// Optimization: quick hack that sets the image size on the tileset
_tileSet->_imageSize = _texture->getContentSizeInPixels();
// By default all the tiles are aliased
// pros: easier to render
// cons: difficult to scale / rotate / etc.
_texture->setAliasTexParameters();
//CFByteOrder o = CFByteOrderGetCurrent();
// Parse cocos2d properties
this->parseInternalProperties();
Size screenSize = Director::getInstance()->getWinSize();
switch (_layerOrientation)
{
case FAST_TMX_ORIENTATION_ORTHO:
_screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 1;
_screenGridSize.height = ceil(screenSize.height / _mapTileSize.height) + 1;
// tiles could be bigger than the grid, add additional rows if needed
_screenGridSize.height += _tileSet->_tileSize.height / _mapTileSize.height;
break;
case FAST_TMX_ORIENTATION_ISO:
_screenGridSize.width = ceil(screenSize.width / _mapTileSize.width) + 2;
_screenGridSize.height = ceil(screenSize.height / (_mapTileSize.height/2)) + 4;
break;
case FAST_TMX_ORIENTATION_HEX:
default:
CCLOGERROR("FastTMX does not support type %d", _layerOrientation);
break;
}
_screenTileCount = _screenGridSize.width * _screenGridSize.height;
}
Mat4 FastTMXLayer::tileToNodeTransform()
{
float w = _mapTileSize.width / CC_CONTENT_SCALE_FACTOR();
float h = _mapTileSize.height / CC_CONTENT_SCALE_FACTOR();
float offY = (_layerSize.height - 1) * h;
switch(_layerOrientation)
{
case FAST_TMX_ORIENTATION_ORTHO:
{
_tileToNodeTransform = Mat4
(
w, 0.0f, 0.0f, 0.0f,
0.0f, -h, 0.0f, offY,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0, 0.0f, 1.0f
);
return _tileToNodeTransform;
}
case FAST_TMX_ORIENTATION_ISO:
{
float offX = (_layerSize.width - 1) * w / 2;
_tileToNodeTransform = Mat4
(
w/2, -w/2, 0.0f, offX,
-h/2, -h/2, 0.0f, offY,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
return _tileToNodeTransform;
}
case FAST_TMX_ORIENTATION_HEX:
{
_tileToNodeTransform = Mat4::IDENTITY;
return _tileToNodeTransform;
}
default:
{
_tileToNodeTransform = Mat4::IDENTITY;
return _tileToNodeTransform;
}
}
}
void FastTMXLayer::updateTotalQuads()
{
if(_quadsDirty)
{
Size tileSize = CC_SIZE_PIXELS_TO_POINTS(_tileSet->_tileSize);
Size texSize = _tileSet->_imageSize;
_tileToQuadIndex.clear();
_totalQuads.resize(int(_layerSize.width * _layerSize.height));
_indices.resize(6 * int(_layerSize.width * _layerSize.height));
_indicesVertexZOffsets.clear();
int quadIndex = 0;
for(int y = 0; y < _layerSize.height; ++y)
{
for(int x =0; x < _layerSize.width; ++x)
{
int tileIndex = getTileIndexByPos(x, y);
int tileGID = _tiles[tileIndex];
if(tileGID == 0) continue;
_tileToQuadIndex[tileIndex] = quadIndex;
auto& quad = _totalQuads[quadIndex];
Vec3 nodePos(float(x), float(y), 0);
_tileToNodeTransform.transformPoint(&nodePos);
float left, right, top, bottom, z;
z = getVertexZForPos(Vec2(x, y));
auto iter = _indicesVertexZOffsets.find(z);
if(iter == _indicesVertexZOffsets.end())
{
_indicesVertexZOffsets[z] = 1;
}
else
{
iter->second++;
}
// vertices
if (tileGID & kTMXTileDiagonalFlag)
{
left = nodePos.x;
right = nodePos.x + tileSize.height;
bottom = nodePos.y + tileSize.width;
top = nodePos.y;
}
else
{
left = nodePos.x;
right = nodePos.x + tileSize.width;
bottom = nodePos.y + tileSize.height;
top = nodePos.y;
}
if(tileGID & kTMXTileVerticalFlag)
std::swap(top, bottom);
if(tileGID & kTMXTileHorizontalFlag)
std::swap(left, right);
if(tileGID & kTMXTileDiagonalFlag)
{
// XXX: not working correcly
quad.bl.vertices.x = left;
quad.bl.vertices.y = bottom;
quad.bl.vertices.z = z;
quad.br.vertices.x = left;
quad.br.vertices.y = top;
quad.br.vertices.z = z;
quad.tl.vertices.x = right;
quad.tl.vertices.y = bottom;
quad.tl.vertices.z = z;
quad.tr.vertices.x = right;
quad.tr.vertices.y = top;
quad.tr.vertices.z = z;
}
else
{
quad.bl.vertices.x = left;
quad.bl.vertices.y = bottom;
quad.bl.vertices.z = z;
quad.br.vertices.x = right;
quad.br.vertices.y = bottom;
quad.br.vertices.z = z;
quad.tl.vertices.x = left;
quad.tl.vertices.y = top;
quad.tl.vertices.z = z;
quad.tr.vertices.x = right;
quad.tr.vertices.y = top;
quad.tr.vertices.z = z;
}
// texcoords
Rect tileTexture = _tileSet->getRectForGID(tileGID);
left = (tileTexture.origin.x / texSize.width);
right = left + (tileTexture.size.width / texSize.width);
bottom = (tileTexture.origin.y / texSize.height);
top = bottom + (tileTexture.size.height / texSize.height);
quad.bl.texCoords.u = left;
quad.bl.texCoords.v = bottom;
quad.br.texCoords.u = right;
quad.br.texCoords.v = bottom;
quad.tl.texCoords.u = left;
quad.tl.texCoords.v = top;
quad.tr.texCoords.u = right;
quad.tr.texCoords.v = top;
quad.bl.colors = Color4B::WHITE;
quad.br.colors = Color4B::WHITE;
quad.tl.colors = Color4B::WHITE;
quad.tr.colors = Color4B::WHITE;
++quadIndex;
}
}
int offset = 0;
for(auto iter = _indicesVertexZOffsets.begin(); iter != _indicesVertexZOffsets.end(); ++iter)
{
std::swap(offset, iter->second);
offset += iter->second;
}
updateVertexBuffer();
_quadsDirty = false;
}
}
// removing / getting tiles
Sprite* FastTMXLayer::getTileAt(const Vec2& tileCoordinate)
{
CCASSERT( tileCoordinate.x < _layerSize.width && tileCoordinate.y < _layerSize.height && tileCoordinate.x >=0 && tileCoordinate.y >=0, "TMXLayer: invalid position");
CCASSERT( _tiles, "TMXLayer: the tiles map has been released");
Sprite *tile = nullptr;
int gid = this->getTileGIDAt(tileCoordinate);
// if GID == 0, then no tile is present
if( gid ) {
int index = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
auto it = _spriteContainer.find(index);
if (it != _spriteContainer.end())
{
tile = it->second.first;
}
else
{
// tile not created yet. create it
Rect rect = _tileSet->getRectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
tile = Sprite::createWithTexture(_texture, rect);
Vec2 p = this->getPositionAt(tileCoordinate);
tile->setAnchorPoint(Vec2::ZERO);
tile->setPosition(p);
tile->setPositionZ((float)getVertexZForPos(tileCoordinate));
tile->setOpacity(this->getOpacity());
tile->setTag(index);
this->addChild(tile, index);
_spriteContainer.insert(std::pair<int, std::pair<Sprite*, int> >(index, std::pair<Sprite*, int>(tile, gid)));
// tile is converted to sprite.
setFlaggedTileGIDByIndex(index, 0);
}
}
return tile;
}
int FastTMXLayer::getTileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags/* = nullptr*/)
{
CCASSERT(tileCoordinate.x < _layerSize.width && tileCoordinate.y < _layerSize.height && tileCoordinate.x >=0 && tileCoordinate.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles, "TMXLayer: the tiles map has been released");
int idx = static_cast<int>((tileCoordinate.x + tileCoordinate.y * _layerSize.width));
// Bits on the far end of the 32-bit global tile ID are used for tile flags
int tile = _tiles[idx];
auto it = _spriteContainer.find(idx);
// converted to sprite.
if (tile == 0 && it != _spriteContainer.end())
{
tile = it->second.second;
}
// issue1264, flipped tiles can be changed dynamically
if (flags)
{
*flags = (TMXTileFlags)(tile & kTMXFlipedAll);
}
return (tile & kTMXFlippedMask);
}
Vec2 FastTMXLayer::getPositionAt(const Vec2& pos)
{
return PointApplyTransform(pos, _tileToNodeTransform);
}
int FastTMXLayer::getVertexZForPos(const Vec2& pos)
{
int ret = 0;
int maxVal = 0;
if (_useAutomaticVertexZ)
{
switch (_layerOrientation)
{
case FAST_TMX_ORIENTATION_ISO:
maxVal = static_cast<int>(_layerSize.width + _layerSize.height);
ret = static_cast<int>(-(maxVal - (pos.x + pos.y)));
break;
case FAST_TMX_ORIENTATION_ORTHO:
ret = static_cast<int>(-(_layerSize.height-pos.y));
break;
case FAST_TMX_ORIENTATION_HEX:
CCASSERT(0, "TMX Hexa zOrder not supported");
break;
default:
CCASSERT(0, "TMX invalid value");
break;
}
}
else
{
ret = _vertexZvalue;
}
return ret;
}
void FastTMXLayer::removeTileAt(const Vec2& tileCoordinate)
{
CCASSERT( tileCoordinate.x < _layerSize.width && tileCoordinate.y < _layerSize.height && tileCoordinate.x >=0 && tileCoordinate.y >=0, "TMXLayer: invalid position");
int gid = this->getTileGIDAt(tileCoordinate);
if( gid ) {
int z = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
// remove tile from GID map
setFlaggedTileGIDByIndex(z, 0);
// remove it from sprites
auto it = _spriteContainer.find(z);
if (it != _spriteContainer.end())
{
this->removeChild(it->second.first);
}
}
}
void FastTMXLayer::setFlaggedTileGIDByIndex(int index, int gid)
{
if(gid == _tiles[index]) return;
_tiles[index] = gid;
_quadsDirty = true;
_dirty = true;
}
void FastTMXLayer::removeChild(Node* node, bool cleanup)
{
int tag = node->getTag();
auto it = _spriteContainer.find(tag);
if (it != _spriteContainer.end() && it->second.first == node)
{
_spriteContainer.erase(it);
}
Node::removeChild(node, cleanup);
}
// FastTMXLayer - Properties
Value FastTMXLayer::getProperty(const std::string& propertyName) const
{
if (_properties.find(propertyName) != _properties.end())
return _properties.at(propertyName);
return Value();
}
void FastTMXLayer::parseInternalProperties()
{
auto vertexz = getProperty("cc_vertexz");
if (vertexz.isNull()) return;
std::string vertexZStr = vertexz.asString();
// If "automatic" is on, then parse the "cc_alpha_func" too
if (vertexZStr == "automatic")
{
_useAutomaticVertexZ = true;
auto alphaFuncVal = getProperty("cc_alpha_func");
float alphaFuncValue = alphaFuncVal.asFloat();
setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST));
GLint alphaValueLocation = glGetUniformLocation(getGLProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
// NOTE: alpha test shader is hard-coded to use the equivalent of a glAlphaFunc(GL_GREATER) comparison
// use shader program to set uniform
getGLProgram()->use();
getGLProgram()->setUniformLocationWith1f(alphaValueLocation, alphaFuncValue);
CHECK_GL_ERROR_DEBUG();
}
else
{
_vertexZvalue = vertexz.asInt();
}
}
//CCTMXLayer2 - obtaining positions, offset
Vec2 FastTMXLayer::calculateLayerOffset(const Vec2& pos)
{
Vec2 ret = Vec2::ZERO;
switch (_layerOrientation)
{
case FAST_TMX_ORIENTATION_ORTHO:
ret = Vec2( pos.x * _mapTileSize.width, -pos.y *_mapTileSize.height);
break;
case FAST_TMX_ORIENTATION_ISO:
ret = Vec2((_mapTileSize.width /2) * (pos.x - pos.y),
(_mapTileSize.height /2 ) * (-pos.x - pos.y));
break;
case FAST_TMX_ORIENTATION_HEX:
default:
CCASSERT(pos.equals(Vec2::ZERO), "offset for this map not implemented yet");
break;
}
return ret;
}
// TMXLayer - adding / remove tiles
void FastTMXLayer::setTileGID(int gid, const Vec2& tileCoordinate)
{
setTileGID(gid, tileCoordinate, (TMXTileFlags)0);
}
void FastTMXLayer::setTileGID(int gid, const Vec2& tileCoordinate, TMXTileFlags flags)
{
CCASSERT(tileCoordinate.x < _layerSize.width && tileCoordinate.y < _layerSize.height && tileCoordinate.x >=0 && tileCoordinate.y >=0, "TMXLayer: invalid position");
CCASSERT(_tiles, "TMXLayer: the tiles map has been released");
CCASSERT(gid == 0 || gid >= _tileSet->_firstGid, "TMXLayer: invalid gid" );
TMXTileFlags currentFlags;
int currentGID = getTileGIDAt(tileCoordinate, &currentFlags);
if (currentGID == gid && currentFlags == flags) return;
int gidAndFlags = gid | flags;
// setting gid=0 is equal to remove the tile
if (gid == 0)
{
removeTileAt(tileCoordinate);
}
// empty tile. create a new one
else if (currentGID == 0)
{
int z = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
setFlaggedTileGIDByIndex(z, gidAndFlags);
}
// modifying an existing tile with a non-empty tile
else
{
int z = tileCoordinate.x + tileCoordinate.y * _layerSize.width;
auto it = _spriteContainer.find(z);
if (it != _spriteContainer.end())
{
Sprite *sprite = it->second.first;
Rect rect = _tileSet->getRectForGID(gid);
rect = CC_RECT_PIXELS_TO_POINTS(rect);
sprite->setTextureRect(rect, false, rect.size);
this->reorderChild(sprite, z);
if (flags)
{
setupTileSprite(sprite, sprite->getPosition(), gidAndFlags);
}
it->second.second = gidAndFlags;
}
else
{
setFlaggedTileGIDByIndex(z, gidAndFlags);
}
}
}
void FastTMXLayer::setupTileSprite(Sprite* sprite, Vec2 pos, int gid)
{
sprite->setPosition(getPositionAt(pos));
sprite->setPositionZ((float)getVertexZForPos(pos));
sprite->setAnchorPoint(Vec2::ZERO);
sprite->setOpacity(this->getOpacity());
//issue 1264, flip can be undone as well
sprite->setFlippedX(false);
sprite->setFlippedY(false);
sprite->setRotation(0.0f);
// Rotation in tiled is achieved using 3 flipped states, flipping across the horizontal, vertical, and diagonal axes of the tiles.
if (gid & kTMXTileDiagonalFlag)
{
// put the anchor in the middle for ease of rotation.
sprite->setAnchorPoint(Vec2(0.5f,0.5f));
sprite->setPosition(Vec2(getPositionAt(pos).x + sprite->getContentSize().height/2,
getPositionAt(pos).y + sprite->getContentSize().width/2 ) );
int flag = gid & (kTMXTileHorizontalFlag | kTMXTileVerticalFlag );
// handle the 4 diagonally flipped states.
if (flag == kTMXTileHorizontalFlag)
{
sprite->setRotation(90.0f);
}
else if (flag == kTMXTileVerticalFlag)
{
sprite->setRotation(270.0f);
}
else if (flag == (kTMXTileVerticalFlag | kTMXTileHorizontalFlag) )
{
sprite->setRotation(90.0f);
sprite->setFlippedX(true);
}
else
{
sprite->setRotation(270.0f);
sprite->setFlippedX(true);
}
}
else
{
if (gid & kTMXTileHorizontalFlag)
{
sprite->setFlippedX(true);
}
if (gid & kTMXTileVerticalFlag)
{
sprite->setFlippedY(true);
}
}
}
std::string FastTMXLayer::getDescription() const
{
return StringUtils::format("<FastTMXLayer | tag = %d, size = %d,%d>", _tag, (int)_mapTileSize.width, (int)_mapTileSize.height);
}
NS_CC_END

262
cocos/2d/CCFastTMXLayer.h Normal file
View File

@ -0,0 +1,262 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CC_FAST_TMX_LAYER_H__
#define __CC_FAST_TMX_LAYER_H__
#include "CCTMXObjectGroup.h"
#include "CCTMXXMLParser.h"
#include "CCNode.h"
#include "renderer/CCCustomCommand.h"
#include "renderer/CCQuadCommand.h"
#include <map>
#include <unordered_map>
NS_CC_BEGIN
class TMXMapInfo;
class TMXLayerInfo;
class TMXTilesetInfo;
class Texture2D;
class Sprite;
struct _ccCArray;
/**
* @addtogroup tilemap_parallax_nodes
* @{
*/
/** @brief FastTMXLayer represents the TMX layer.
It is a subclass of SpriteBatchNode. By default the tiles are rendered using a TextureAtlas.
If you modify a tile on runtime, then, that tile will become a Sprite, otherwise no Sprite objects are created.
The benefits of using Sprite objects as tiles are:
- tiles (Sprite) can be rotated/scaled/moved with a nice API
If the layer contains a property named "cc_vertexz" with an integer (in can be positive or negative),
then all the tiles belonging to the layer will use that value as their OpenGL vertex Z for depth.
On the other hand, if the "cc_vertexz" property has the "automatic" value, then the tiles will use an automatic vertex Z value.
Also before drawing the tiles, GL_ALPHA_TEST will be enabled, and disabled after drawing them. The used alpha func will be:
glAlphaFunc( GL_GREATER, value )
"value" by default is 0, but you can change it from Tiled by adding the "cc_alpha_func" property to the layer.
The value 0 should work for most cases, but if you have tiles that are semi-transparent, then you might want to use a different
value, like 0.5.
For further information, please see the programming guide:
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:tiled_maps
@since v3.2
*/
class CC_DLL FastTMXLayer : public Node
{
public:
/** creates a FastTMXLayer with an tileset info, a layer info and a map info */
static FastTMXLayer * create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
/**
* @js ctor
*/
FastTMXLayer();
/**
* @js NA
* @lua NA
*/
virtual ~FastTMXLayer();
/** returns the tile gid at a given tile coordinate. It also returns the tile flags.
*/
int getTileGIDAt(const Vec2& tileCoordinate, TMXTileFlags* flags = nullptr);
/** sets the tile gid (gid = tile global id) at a given tile coordinate.
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
If a tile is already placed at that position, then it will be removed.
*/
void setTileGID(int gid, const Vec2& tileCoordinate);
/** sets the tile gid (gid = tile global id) at a given tile coordinate.
The Tile GID can be obtained by using the method "tileGIDAt" or by using the TMX editor -> Tileset Mgr +1.
If a tile is already placed at that position, then it will be removed.
Use withFlags if the tile flags need to be changed as well
*/
void setTileGID(int gid, const Vec2& tileCoordinate, TMXTileFlags flags);
/** removes a tile at given tile coordinate */
void removeTileAt(const Vec2& tileCoordinate);
/** returns the position in points of a given tile coordinate */
Vec2 getPositionAt(const Vec2& tileCoordinate);
/** return the value for the specific property name */
Value getProperty(const std::string& propertyName) const;
/** Creates the tiles */
void setupTiles();
inline const std::string& getLayerName(){ return _layerName; }
inline void setLayerName(const std::string& layerName){ _layerName = layerName; }
/** size of the layer in tiles */
inline const Size& getLayerSize() const { return _layerSize; };
inline void setLayerSize(const Size& size) { _layerSize = size; };
/** size of the map's tile (could be different from the tile's size) */
inline const Size& getMapTileSize() const { return _mapTileSize; };
inline void setMapTileSize(const Size& size) { _mapTileSize = size; };
/** pointer to the map of tiles
* @js NA
* @lua NA
*/
const uint32_t* getTiles() const { return _tiles; };
void setTiles(uint32_t* tiles) { _tiles = tiles; _quadsDirty = true;};
/** Tileset information for the layer */
inline TMXTilesetInfo* getTileSet() const { return _tileSet; };
inline void setTileSet(TMXTilesetInfo* info) {
CC_SAFE_RETAIN(info);
CC_SAFE_RELEASE(_tileSet);
_tileSet = info;
};
/** Layer orientation, which is the same as the map orientation */
inline int getLayerOrientation() const { return _layerOrientation; };
inline void setLayerOrientation(int orientation) { _layerOrientation = orientation; };
/** properties from the layer. They can be added using Tiled */
inline const ValueMap& getProperties() const { return _properties; };
inline ValueMap& getProperties() { return _properties; };
inline void setProperties(const ValueMap& properties)
{
_properties = properties;
};
/** returns the tile (Sprite) at a given a tile coordinate.
The returned Sprite will be already added to the TMXLayer. Don't add it again.
The Sprite can be treated like any other Sprite: rotated, scaled, translated, opacity, color, etc.
You can remove either by calling:
- layer->removeChild(sprite, cleanup);
*/
Sprite* getTileAt(const Vec2& tileCoordinate);
void setupTileSprite(Sprite* sprite, Vec2 pos, int gid);
//
// Override
//
virtual std::string getDescription() const override;
virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;
void removeChild(Node* child, bool cleanup = true) override;
protected:
bool initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
void updateTiles(const Rect& culledRect);
Vec2 calculateLayerOffset(const Vec2& offset);
/* The layer recognizes some special properties, like cc_vertez */
void parseInternalProperties();
Mat4 tileToNodeTransform();
Rect tileBoundsForClipTransform(const Mat4 &tileToClip);
int getVertexZForPos(const Vec2& pos);
//Flip flags is packed into gid
void setFlaggedTileGIDByIndex(int index, int gid);
//
void updateTotalQuads();
void onDraw(int offset, int count);
inline int getTileIndexByPos(int x, int y) const { return x + y * (int) _layerSize.width; }
void updateVertexBuffer();
void updateIndexBuffer();
protected:
//! name of the layer
std::string _layerName;
/** size of the layer in tiles */
Size _layerSize;
/** size of the map's tile (could be different from the tile's size) */
Size _mapTileSize;
/** pointer to the map of tiles */
uint32_t* _tiles;
/** Tileset information for the layer */
TMXTilesetInfo* _tileSet;
/** Layer orientation, which is the same as the map orientation */
int _layerOrientation;
/** properties from the layer. They can be added using Tiled */
ValueMap _properties;
Texture2D *_texture;
/** container for sprite children. map<index, pair<sprite, gid> > */
std::map<int, std::pair<Sprite*, int> > _spriteContainer;
GLuint _buffersVBO[2]; //0: vertex, 1: indices
Size _screenGridSize;
Rect _screenGridRect;
int _screenTileCount;
int _vertexZvalue;
bool _useAutomaticVertexZ;
/** tile coordinate to node coordinate transform */
Mat4 _tileToNodeTransform;
/** data for rendering */
bool _quadsDirty;
std::unordered_map<ssize_t, ssize_t> _tileToQuadIndex;
std::vector<V3F_C4B_T2F_Quad> _totalQuads;
std::vector<int> _indices;
std::map<int/*vertexZ*/, int/*offset to _indices by quads*/> _indicesVertexZOffsets;
std::unordered_map<int/*vertexZ*/, int/*number to quads*/> _indicesVertexZNumber;
std::vector<CustomCommand> _renderCommands;
bool _dirty;
public:
/** Possible orientations of the TMX map */
static const int FAST_TMX_ORIENTATION_ORTHO;
static const int FAST_TMX_ORIENTATION_HEX;
static const int FAST_TMX_ORIENTATION_ISO;
};
// end of tilemap_parallax_nodes group
/// @}
NS_CC_END
#endif //__CCTMX_LAYER2_H__

View File

@ -0,0 +1,256 @@
/****************************************************************************
Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCFastTMXTiledMap.h"
#include <algorithm>
#include "CCTMXXMLParser.h"
#include "CCFastTMXLayer.h"
#include "CCSprite.h"
#include "deprecated/CCString.h"
NS_CC_BEGIN
// implementation FastTMXTiledMap
FastTMXTiledMap * FastTMXTiledMap::create(const std::string& tmxFile)
{
FastTMXTiledMap *ret = new FastTMXTiledMap();
if (ret->initWithTMXFile(tmxFile))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
FastTMXTiledMap* FastTMXTiledMap::createWithXML(const std::string& tmxString, const std::string& resourcePath)
{
FastTMXTiledMap *ret = new FastTMXTiledMap();
if (ret->initWithXML(tmxString, resourcePath))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
bool FastTMXTiledMap::initWithTMXFile(const std::string& tmxFile)
{
CCASSERT(tmxFile.size()>0, "FastTMXTiledMap: tmx file should not be empty");
setContentSize(Size::ZERO);
TMXMapInfo *mapInfo = TMXMapInfo::create(tmxFile);
if (! mapInfo)
{
return false;
}
CCASSERT( !mapInfo->getTilesets().empty(), "FastTMXTiledMap: Map not found. Please check the filename.");
buildWithMapInfo(mapInfo);
return true;
}
bool FastTMXTiledMap::initWithXML(const std::string& tmxString, const std::string& resourcePath)
{
setContentSize(Size::ZERO);
TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath);
CCASSERT( !mapInfo->getTilesets().empty(), "FastTMXTiledMap: Map not found. Please check the filename.");
buildWithMapInfo(mapInfo);
return true;
}
FastTMXTiledMap::FastTMXTiledMap()
:_mapSize(Size::ZERO)
,_tileSize(Size::ZERO)
{
}
FastTMXTiledMap::~FastTMXTiledMap()
{
}
// private
FastTMXLayer * FastTMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
FastTMXLayer *layer = FastTMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->_ownTiles = false;
layer->setupTiles();
return layer;
}
TMXTilesetInfo * FastTMXTiledMap::tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
Size size = layerInfo->_layerSize;
auto& tilesets = mapInfo->getTilesets();
for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter)
{
TMXTilesetInfo* tilesetInfo = *iter;
if (tilesetInfo)
{
for( int y=0; y < size.height; y++ )
{
for( int x=0; x < size.width; x++ )
{
int pos = static_cast<int>(x + size.width * y);
int gid = layerInfo->_tiles[ pos ];
// gid are stored in little endian.
// if host is big endian, then swap
//if( o == CFByteOrderBigEndian )
// gid = CFSwapInt32( gid );
/* We support little endian.*/
// XXX: gid == 0 --> empty tile
if( gid != 0 )
{
// Optimization: quick return
// if the layer is invalid (more than 1 tileset per layer) an CCAssert will be thrown later
if( (gid & kTMXFlippedMask) >= tilesetInfo->_firstGid )
return tilesetInfo;
}
}
}
}
}
// If all the tiles are 0, return empty tileset
CCLOG("cocos2d: Warning: TMX Layer '%s' has no tiles", layerInfo->_name.c_str());
return nullptr;
}
void FastTMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
{
_mapSize = mapInfo->getMapSize();
_tileSize = mapInfo->getTileSize();
_mapOrientation = mapInfo->getOrientation();
_objectGroups = mapInfo->getObjectGroups();
_properties = mapInfo->getProperties();
_tileProperties = mapInfo->getTileProperties();
int idx=0;
auto& layers = mapInfo->getLayers();
for(const auto &layerInfo : layers) {
if (layerInfo->_visible)
{
FastTMXLayer *child = parseLayer(layerInfo, mapInfo);
addChild(child, idx, idx);
// update content size with the max size
const Size& childSize = child->getContentSize();
Size currentSize = this->getContentSize();
currentSize.width = std::max( currentSize.width, childSize.width );
currentSize.height = std::max( currentSize.height, childSize.height );
this->setContentSize(currentSize);
idx++;
}
}
}
// public
FastTMXLayer * FastTMXTiledMap::getLayer(const std::string& layerName) const
{
CCASSERT(layerName.size() > 0, "Invalid layer name!");
for (auto& child : _children)
{
FastTMXLayer* layer = dynamic_cast<FastTMXLayer*>(child);
if(layer)
{
if(layerName.compare( layer->getLayerName()) == 0)
{
return layer;
}
}
}
// layer not found
return nullptr;
}
TMXObjectGroup * FastTMXTiledMap::getObjectGroup(const std::string& groupName) const
{
CCASSERT(groupName.size() > 0, "Invalid group name!");
if (_objectGroups.size()>0)
{
TMXObjectGroup* objectGroup = nullptr;
for (auto iter = _objectGroups.cbegin(); iter != _objectGroups.cend(); ++iter)
{
objectGroup = *iter;
if (objectGroup && objectGroup->getGroupName() == groupName)
{
return objectGroup;
}
}
}
// objectGroup not found
return nullptr;
}
Value FastTMXTiledMap::getProperty(const std::string& propertyName) const
{
if (_properties.find(propertyName) != _properties.end())
return _properties.at(propertyName);
return Value();
}
Value FastTMXTiledMap::getPropertiesForGID(int GID) const
{
if (_tileProperties.find(GID) != _tileProperties.end())
return _tileProperties.at(GID);
return Value();
}
std::string FastTMXTiledMap::getDescription() const
{
return StringUtils::format("<FastTMXTiledMap | Tag = %d, Layers = %d", _tag, static_cast<int>(_children.size()));
}
NS_CC_END

View File

@ -0,0 +1,187 @@
/****************************************************************************
Copyright (c) 2009-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CC_FAST_TMX_TILEMAP_H__
#define __CC_FAST_TMX_TILEMAP_H__
#include "CCNode.h"
#include "CCTMXObjectGroup.h"
NS_CC_BEGIN
class TMXObjectGroup;
class FastTMXLayer;
class TMXLayerInfo;
class TMXTilesetInfo;
class TMXMapInfo;
/** @brief FastTMXTiledMap knows how to parse and render a TMX map.
It adds support for the TMX tiled map format used by http://www.mapeditor.org
It supports isometric, hexagonal and orthogonal tiles.
It also supports object groups, objects, and properties.
Features:
- Each tile will be treated as an Sprite
- The sprites are created on demand. They will be created only when you call "layer->tileAt(position)"
- Each tile can be rotated / moved / scaled / tinted / "opaqued", since each tile is a Sprite
- Tiles can be added/removed in runtime
- The z-order of the tiles can be modified in runtime
- Each tile has an anchorPoint of (0,0)
- The anchorPoint of the TMXTileMap is (0,0)
- The TMX layers will be added as a child
- The TMX layers will be aliased by default
- The tileset image will be loaded using the TextureCache
- Each tile will have a unique tag
- Each tile will have a unique z value. top-left: z=1, bottom-right: z=max z
- Each object group will be treated as an MutableArray
- Object class which will contain all the properties in a dictionary
- Properties can be assigned to the Map, Layer, Object Group, and Object
Limitations:
- It only supports one tileset per layer.
- Embedded images are not supported
- It only supports the XML format (the JSON format is not supported)
Technical description:
Each layer is created using an FastTMXLayer (subclass of SpriteBatchNode). If you have 5 layers, then 5 FastTMXLayer will be created,
unless the layer visibility is off. In that case, the layer won't be created at all.
You can obtain the layers (FastTMXLayer objects) at runtime by:
- map->getChildByTag(tag_number); // 0=1st layer, 1=2nd layer, 2=3rd layer, etc...
- map->getLayer(name_of_the_layer);
Each object group is created using a TMXObjectGroup which is a subclass of MutableArray.
You can obtain the object groups at runtime by:
- map->getObjectGroup(name_of_the_object_group);
Each object is a TMXObject.
Each property is stored as a key-value pair in an MutableDictionary.
You can obtain the properties at runtime by:
map->getProperty(name_of_the_property);
layer->getProperty(name_of_the_property);
objectGroup->getProperty(name_of_the_property);
object->getProperty(name_of_the_property);
@since v3.2
*/
class CC_DLL FastTMXTiledMap : public Node
{
public:
/** creates a TMX Tiled Map with a TMX file.*/
static FastTMXTiledMap* create(const std::string& tmxFile);
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
static FastTMXTiledMap* createWithXML(const std::string& tmxString, const std::string& resourcePath);
/** return the FastTMXLayer for the specific layer */
FastTMXLayer* getLayer(const std::string& layerName) const;
/** return the TMXObjectGroup for the specific group */
TMXObjectGroup* getObjectGroup(const std::string& groupName) const;
/** return the value for the specific property name */
Value getProperty(const std::string& propertyName) const;
/** return properties dictionary for tile GID */
Value getPropertiesForGID(int GID) const;
/** the map's size property measured in tiles */
inline const Size& getMapSize() const { return _mapSize; };
inline void setMapSize(const Size& mapSize) { _mapSize = mapSize; };
/** the tiles's size property measured in pixels */
inline const Size& getTileSize() const { return _tileSize; };
inline void setTileSize(const Size& tileSize) { _tileSize = tileSize; };
/** map orientation */
inline int getMapOrientation() const { return _mapOrientation; };
inline void setMapOrientation(int mapOrientation) { _mapOrientation = mapOrientation; };
/** object groups */
inline const Vector<TMXObjectGroup*>& getObjectGroups() const { return _objectGroups; };
inline Vector<TMXObjectGroup*>& getObjectGroups() { return _objectGroups; };
inline void setObjectGroups(const Vector<TMXObjectGroup*>& groups) {
_objectGroups = groups;
};
/** properties */
inline const ValueMap& getProperties() const { return _properties; };
inline void setProperties(const ValueMap& properties) {
_properties = properties;
};
virtual std::string getDescription() const override;
protected:
/**
* @js ctor
*/
FastTMXTiledMap();
/**
* @js NA
* @lua NA
*/
virtual ~FastTMXTiledMap();
/** initializes a TMX Tiled Map with a TMX file */
bool initWithTMXFile(const std::string& tmxFile);
/** initializes a TMX Tiled Map with a TMX formatted XML string and a path to TMX resources */
bool initWithXML(const std::string& tmxString, const std::string& resourcePath);
FastTMXLayer * parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
TMXTilesetInfo * tilesetForLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo);
void buildWithMapInfo(TMXMapInfo* mapInfo);
/** the map's size property measured in tiles */
Size _mapSize;
/** the tiles's size property measured in pixels */
Size _tileSize;
/** map orientation */
int _mapOrientation;
/** object groups */
Vector<TMXObjectGroup*> _objectGroups;
/** properties */
ValueMap _properties;
//! tile properties
ValueMapIntKey _tileProperties;
private:
CC_DISALLOW_COPY_AND_ASSIGN(FastTMXTiledMap);
};
// end of tilemap_parallax_nodes group
/// @}
NS_CC_END
#endif //__CCTMX_TILE_MAP2_H__

View File

@ -30,6 +30,8 @@ set(COCOS_2D_SRC
2d/CCComponent.cpp
2d/CCDrawingPrimitives.cpp
2d/CCDrawNode.cpp
2d/CCFastTMXLayer.cpp
2d/CCFastTMXTiledMap.cpp
2d/CCFontAtlasCache.cpp
2d/CCFontAtlas.cpp
2d/CCFontCharMap.cpp

View File

@ -306,6 +306,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
<ClCompile Include="CCComponentContainer.cpp" />
<ClCompile Include="CCDrawingPrimitives.cpp" />
<ClCompile Include="CCDrawNode.cpp" />
<ClCompile Include="CCFastTMXLayer.cpp" />
<ClCompile Include="CCFastTMXTiledMap.cpp" />
<ClCompile Include="CCFont.cpp" />
<ClCompile Include="CCFontAtlas.cpp" />
<ClCompile Include="CCFontAtlasCache.cpp" />
@ -509,6 +511,8 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32-specific\gles\prebuilt\*.*" "$(Ou
<ClInclude Include="CCComponentContainer.h" />
<ClInclude Include="CCDrawingPrimitives.h" />
<ClInclude Include="CCDrawNode.h" />
<ClInclude Include="CCFastTMXLayer.h" />
<ClInclude Include="CCFastTMXTiledMap.h" />
<ClInclude Include="CCFont.h" />
<ClInclude Include="CCFontAtlas.h" />
<ClInclude Include="CCFontAtlasCache.h" />

View File

@ -583,6 +583,12 @@
<ClCompile Include="..\3d\CCBundleReader.cpp">
<Filter>3d</Filter>
</ClCompile>
<ClCompile Include="CCFastTMXLayer.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="CCFastTMXTiledMap.cpp">
<Filter>2d</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h">
@ -1186,6 +1192,12 @@
<ClInclude Include="..\3d\CCBundleReader.h">
<Filter>3d</Filter>
</ClInclude>
<ClInclude Include="CCFastTMXTiledMap.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="CCFastTMXLayer.h">
<Filter>2d</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -62,8 +62,10 @@ cocos2d.cpp \
2d/CCSpriteFrame.cpp \
2d/CCSpriteFrameCache.cpp \
2d/CCTMXLayer.cpp \
2d/CCFastTMXLayer.cpp \
2d/CCTMXObjectGroup.cpp \
2d/CCTMXTiledMap.cpp \
2d/CCFastTMXTiledMap.cpp \
2d/CCTMXXMLParser.cpp \
2d/CCTextFieldTTF.cpp \
2d/CCTileMapAtlas.cpp \

View File

@ -254,6 +254,15 @@ struct V3F_C4B_T2F
Tex2F texCoords; // 8 bytes
};
//! a Vec2 with a vertex point, a tex coord point
struct V3F_T2F
{
//! vertices (2F)
Vec3 vertices;
//! tex coords (2F)
Tex2F texCoords;
};
//! A Triangle of V2F_C4B_T2F
struct V2F_C4B_T2F_Triangle
{
@ -304,6 +313,18 @@ struct V2F_C4F_T2F_Quad
V2F_C4F_T2F tr;
};
struct V3F_T2F_Quad
{
//! bottom left
V3F_T2F bl;
//! bottom right
V3F_T2F br;
//! top left
V3F_T2F tl;
//! top right
V3F_T2F tr;
};
//! Blend Function used for textures
struct BlendFunc
{

View File

@ -57,8 +57,8 @@ WidgetReader/TextReader/TextReader.cpp \
ActionTimeline/CCNodeReader.cpp \
ActionTimeline/CCActionTimelineCache.cpp \
ActionTimeline/CCFrame.cpp \
ActionTimeline/CCTimeline.cpp \
ActionTimeline/CCActionTimeline.cpp \
ActionTimeline/CCTimeLine.cpp \
ActionTimeline/CCActionTimeline.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \
$(LOCAL_PATH)/../../../external

View File

@ -408,6 +408,10 @@ void Armature::draw(cocos2d::Renderer *renderer, const Mat4 &transform, uint32_t
{
skin->setBlendFunc(bone->getBlendFunc());
}
else
{
skin->setBlendFunc(_blendFunc);
}
skin->draw(renderer, transform, flags);
}
break;

View File

@ -342,6 +342,12 @@ void ArmatureAnimation::update(float dt)
tween->update(dt);
}
if(_frameEventQueue.size() > 0 || _movementEventQueue.size() > 0)
{
_armature->retain();
_armature->autorelease();
}
while (_frameEventQueue.size() > 0)
{
FrameEvent *event = _frameEventQueue.front();

View File

@ -47,7 +47,6 @@ public:
void useMaterial() const;
inline uint32_t getMaterialID() const { return _materialID; }
inline GLuint getTextureID() const { return _textureID; }
inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; }
@ -55,7 +54,6 @@ public:
inline GLProgramState* getGLProgramState() const { return _glProgramState; }
inline BlendFunc getBlendType() const { return _blendType; }
inline const Mat4& getModelView() const { return _mv; }
protected:
void generateMaterialID();
@ -68,6 +66,7 @@ protected:
ssize_t _quadsCount;
Mat4 _mv;
};
NS_CC_END
#endif //_CC_QUADCOMMAND_H_

View File

@ -1,14 +1,9 @@
--------------------------------
-- @module PhysicsShapeBox
-- @extend PhysicsShape
-- @extend PhysicsShapePolygon
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsShapeBox] getPointsCount
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
-- @function [parent=#PhysicsShapeBox] getSize
-- @param self
@ -22,28 +17,9 @@
-- @param #vec2_table vec2
-- @return PhysicsShapeBox#PhysicsShapeBox ret (return value: cc.PhysicsShapeBox)
--------------------------------
-- @function [parent=#PhysicsShapeBox] calculateArea
-- @param self
-- @param #size_table size
-- @return float#float ret (return value: float)
--------------------------------
-- @function [parent=#PhysicsShapeBox] calculateMoment
-- @param self
-- @param #float float
-- @param #size_table size
-- @param #vec2_table vec2
-- @return float#float ret (return value: float)
--------------------------------
-- @function [parent=#PhysicsShapeBox] getOffset
-- @param self
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- @function [parent=#PhysicsShapeBox] calculateDefaultMoment
-- @param self
-- @return float#float ret (return value: float)
return nil

View File

@ -1,14 +1,9 @@
--------------------------------
-- @module PhysicsShapeEdgeBox
-- @extend PhysicsShape
-- @extend PhysicsShapeEdgePolygon
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsShapeEdgeBox] getPointsCount
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
-- @function [parent=#PhysicsShapeEdgeBox] create
-- @param self

View File

@ -22,13 +22,13 @@
--------------------------------------------------------
-- the cc PhysicsShapeBox
-- @field [parent=#cc] PhysicsShapeBox#PhysicsShapeBox PhysicsShapeBox preloaded module
-- the cc PhysicsShapePolygon
-- @field [parent=#cc] PhysicsShapePolygon#PhysicsShapePolygon PhysicsShapePolygon preloaded module
--------------------------------------------------------
-- the cc PhysicsShapePolygon
-- @field [parent=#cc] PhysicsShapePolygon#PhysicsShapePolygon PhysicsShapePolygon preloaded module
-- the cc PhysicsShapeBox
-- @field [parent=#cc] PhysicsShapeBox#PhysicsShapeBox PhysicsShapeBox preloaded module
--------------------------------------------------------
@ -37,13 +37,13 @@
--------------------------------------------------------
-- the cc PhysicsShapeEdgeBox
-- @field [parent=#cc] PhysicsShapeEdgeBox#PhysicsShapeEdgeBox PhysicsShapeEdgeBox preloaded module
-- the cc PhysicsShapeEdgePolygon
-- @field [parent=#cc] PhysicsShapeEdgePolygon#PhysicsShapeEdgePolygon PhysicsShapeEdgePolygon preloaded module
--------------------------------------------------------
-- the cc PhysicsShapeEdgePolygon
-- @field [parent=#cc] PhysicsShapeEdgePolygon#PhysicsShapeEdgePolygon PhysicsShapeEdgePolygon preloaded module
-- the cc PhysicsShapeEdgeBox
-- @field [parent=#cc] PhysicsShapeEdgeBox#PhysicsShapeEdgeBox PhysicsShapeEdgeBox preloaded module
--------------------------------------------------------

View File

@ -2416,259 +2416,6 @@ int lua_register_cocos2dx_physics_PhysicsShapeCircle(lua_State* tolua_S)
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeBox_getPointsCount(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsShapeBox* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsShapeBox*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeBox_getPointsCount'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
int ret = cobj->getPointsCount();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getPointsCount",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_getPointsCount'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsShapeBox_getSize(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsShapeBox* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsShapeBox*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeBox_getSize'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
cocos2d::Size ret = cobj->getSize();
size_to_luaval(tolua_S, ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSize",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_getSize'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsShapeBox_create(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
cocos2d::Size arg0;
ok &= luaval_to_size(tolua_S, 2, &arg0);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
if (argc == 2)
{
cocos2d::Size arg0;
cocos2d::PhysicsMaterial arg1;
ok &= luaval_to_size(tolua_S, 2, &arg0);
ok &= luaval_to_physics_material(tolua_S, 3, &arg1);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0, arg1);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
if (argc == 3)
{
cocos2d::Size arg0;
cocos2d::PhysicsMaterial arg1;
cocos2d::Vec2 arg2;
ok &= luaval_to_size(tolua_S, 2, &arg0);
ok &= luaval_to_physics_material(tolua_S, 3, &arg1);
ok &= luaval_to_vec2(tolua_S, 4, &arg2);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "create",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_create'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsShapeBox_calculateArea(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
cocos2d::Size arg0;
ok &= luaval_to_size(tolua_S, 2, &arg0);
if(!ok)
return 0;
double ret = cocos2d::PhysicsShapeBox::calculateArea(arg0);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "calculateArea",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_calculateArea'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsShapeBox_calculateMoment(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 2)
{
double arg0;
cocos2d::Size arg1;
ok &= luaval_to_number(tolua_S, 2,&arg0);
ok &= luaval_to_size(tolua_S, 3, &arg1);
if(!ok)
return 0;
double ret = cocos2d::PhysicsShapeBox::calculateMoment(arg0, arg1);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
if (argc == 3)
{
double arg0;
cocos2d::Size arg1;
cocos2d::Vec2 arg2;
ok &= luaval_to_number(tolua_S, 2,&arg0);
ok &= luaval_to_size(tolua_S, 3, &arg1);
ok &= luaval_to_vec2(tolua_S, 4, &arg2);
if(!ok)
return 0;
double ret = cocos2d::PhysicsShapeBox::calculateMoment(arg0, arg1, arg2);
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "calculateMoment",argc, 2);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_calculateMoment'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_PhysicsShapeBox_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (PhysicsShapeBox)");
return 0;
}
int lua_register_cocos2dx_physics_PhysicsShapeBox(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsShapeBox");
tolua_cclass(tolua_S,"PhysicsShapeBox","cc.PhysicsShapeBox","cc.PhysicsShape",nullptr);
tolua_beginmodule(tolua_S,"PhysicsShapeBox");
tolua_function(tolua_S,"getPointsCount",lua_cocos2dx_physics_PhysicsShapeBox_getPointsCount);
tolua_function(tolua_S,"getSize",lua_cocos2dx_physics_PhysicsShapeBox_getSize);
tolua_function(tolua_S,"create", lua_cocos2dx_physics_PhysicsShapeBox_create);
tolua_function(tolua_S,"calculateArea", lua_cocos2dx_physics_PhysicsShapeBox_calculateArea);
tolua_function(tolua_S,"calculateMoment", lua_cocos2dx_physics_PhysicsShapeBox_calculateMoment);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsShapeBox).name();
g_luaType[typeName] = "cc.PhysicsShapeBox";
g_typeCast["PhysicsShapeBox"] = "cc.PhysicsShapeBox";
return 1;
}
int lua_cocos2dx_physics_PhysicsShapePolygon_getPointsCount(lua_State* tolua_S)
{
int argc = 0;
@ -2781,6 +2528,130 @@ int lua_register_cocos2dx_physics_PhysicsShapePolygon(lua_State* tolua_S)
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeBox_getSize(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsShapeBox* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsShapeBox*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeBox_getSize'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
cocos2d::Size ret = cobj->getSize();
size_to_luaval(tolua_S, ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getSize",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_getSize'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsShapeBox_create(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.PhysicsShapeBox",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
cocos2d::Size arg0;
ok &= luaval_to_size(tolua_S, 2, &arg0);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
if (argc == 2)
{
cocos2d::Size arg0;
cocos2d::PhysicsMaterial arg1;
ok &= luaval_to_size(tolua_S, 2, &arg0);
ok &= luaval_to_physics_material(tolua_S, 3, &arg1);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0, arg1);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
if (argc == 3)
{
cocos2d::Size arg0;
cocos2d::PhysicsMaterial arg1;
cocos2d::Vec2 arg2;
ok &= luaval_to_size(tolua_S, 2, &arg0);
ok &= luaval_to_physics_material(tolua_S, 3, &arg1);
ok &= luaval_to_vec2(tolua_S, 4, &arg2);
if(!ok)
return 0;
cocos2d::PhysicsShapeBox* ret = cocos2d::PhysicsShapeBox::create(arg0, arg1, arg2);
object_to_luaval<cocos2d::PhysicsShapeBox>(tolua_S, "cc.PhysicsShapeBox",(cocos2d::PhysicsShapeBox*)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d\n ", "create",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeBox_create'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_PhysicsShapeBox_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (PhysicsShapeBox)");
return 0;
}
int lua_register_cocos2dx_physics_PhysicsShapeBox(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsShapeBox");
tolua_cclass(tolua_S,"PhysicsShapeBox","cc.PhysicsShapeBox","cc.PhysicsShapePolygon",nullptr);
tolua_beginmodule(tolua_S,"PhysicsShapeBox");
tolua_function(tolua_S,"getSize",lua_cocos2dx_physics_PhysicsShapeBox_getSize);
tolua_function(tolua_S,"create", lua_cocos2dx_physics_PhysicsShapeBox_create);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsShapeBox).name();
g_luaType[typeName] = "cc.PhysicsShapeBox";
g_typeCast["PhysicsShapeBox"] = "cc.PhysicsShapeBox";
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeEdgeSegment_getPointB(lua_State* tolua_S)
{
int argc = 0;
@ -2956,10 +2827,10 @@ int lua_register_cocos2dx_physics_PhysicsShapeEdgeSegment(lua_State* tolua_S)
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount(lua_State* tolua_S)
int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsShapeEdgeBox* cobj = nullptr;
cocos2d::PhysicsShapeEdgePolygon* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
@ -2968,15 +2839,15 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgeBox",0,&tolua_err)) goto tolua_lerror;
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgePolygon",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsShapeEdgeBox*)tolua_tousertype(tolua_S,1,0);
cobj = (cocos2d::PhysicsShapeEdgePolygon*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount'", nullptr);
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount'", nullptr);
return 0;
}
#endif
@ -2995,11 +2866,31 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount'.",&tolua_err);
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (PhysicsShapeEdgePolygon)");
return 0;
}
int lua_register_cocos2dx_physics_PhysicsShapeEdgePolygon(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsShapeEdgePolygon");
tolua_cclass(tolua_S,"PhysicsShapeEdgePolygon","cc.PhysicsShapeEdgePolygon","cc.PhysicsShape",nullptr);
tolua_beginmodule(tolua_S,"PhysicsShapeEdgePolygon");
tolua_function(tolua_S,"getPointsCount",lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsShapeEdgePolygon).name();
g_luaType[typeName] = "cc.PhysicsShapeEdgePolygon";
g_typeCast["PhysicsShapeEdgePolygon"] = "cc.PhysicsShapeEdgePolygon";
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeEdgeBox_create(lua_State* tolua_S)
{
int argc = 0;
@ -3084,10 +2975,9 @@ static int lua_cocos2dx_physics_PhysicsShapeEdgeBox_finalize(lua_State* tolua_S)
int lua_register_cocos2dx_physics_PhysicsShapeEdgeBox(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsShapeEdgeBox");
tolua_cclass(tolua_S,"PhysicsShapeEdgeBox","cc.PhysicsShapeEdgeBox","cc.PhysicsShape",nullptr);
tolua_cclass(tolua_S,"PhysicsShapeEdgeBox","cc.PhysicsShapeEdgeBox","cc.PhysicsShapeEdgePolygon",nullptr);
tolua_beginmodule(tolua_S,"PhysicsShapeEdgeBox");
tolua_function(tolua_S,"getPointsCount",lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPointsCount);
tolua_function(tolua_S,"create", lua_cocos2dx_physics_PhysicsShapeEdgeBox_create);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsShapeEdgeBox).name();
@ -3096,70 +2986,6 @@ int lua_register_cocos2dx_physics_PhysicsShapeEdgeBox(lua_State* tolua_S)
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsShapeEdgePolygon* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsShapeEdgePolygon",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsShapeEdgePolygon*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
int ret = cobj->getPointsCount();
tolua_pushnumber(tolua_S,(lua_Number)ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getPointsCount",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (PhysicsShapeEdgePolygon)");
return 0;
}
int lua_register_cocos2dx_physics_PhysicsShapeEdgePolygon(lua_State* tolua_S)
{
tolua_usertype(tolua_S,"cc.PhysicsShapeEdgePolygon");
tolua_cclass(tolua_S,"PhysicsShapeEdgePolygon","cc.PhysicsShapeEdgePolygon","cc.PhysicsShape",nullptr);
tolua_beginmodule(tolua_S,"PhysicsShapeEdgePolygon");
tolua_function(tolua_S,"getPointsCount",lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPointsCount);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::PhysicsShapeEdgePolygon).name();
g_luaType[typeName] = "cc.PhysicsShapeEdgePolygon";
g_typeCast["PhysicsShapeEdgePolygon"] = "cc.PhysicsShapeEdgePolygon";
return 1;
}
int lua_cocos2dx_physics_PhysicsShapeEdgeChain_getPointsCount(lua_State* tolua_S)
{
int argc = 0;
@ -11090,6 +10916,7 @@ TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S)
lua_register_cocos2dx_physics_EventListenerPhysicsContact(tolua_S);
lua_register_cocos2dx_physics_EventListenerPhysicsContactWithGroup(tolua_S);
lua_register_cocos2dx_physics_PhysicsShape(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapePolygon(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapeBox(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointMotor(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointRatchet(tolua_S);
@ -11103,7 +10930,6 @@ TOLUA_API int register_all_cocos2dx_physics(lua_State* tolua_S)
lua_register_cocos2dx_physics_PhysicsShapeEdgeSegment(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointGear(tolua_S);
lua_register_cocos2dx_physics_PhysicsContact(tolua_S);
lua_register_cocos2dx_physics_PhysicsShapePolygon(tolua_S);
lua_register_cocos2dx_physics_EventListenerPhysicsContactWithBodies(tolua_S);
lua_register_cocos2dx_physics_PhysicsJointRotarySpring(tolua_S);
lua_register_cocos2dx_physics_PhysicsContactPostSolve(tolua_S);

View File

@ -255,10 +255,6 @@ int register_all_cocos2dx_physics(lua_State* tolua_S);

View File

@ -91,6 +91,10 @@
"cocos/2d/CCDrawNode.h",
"cocos/2d/CCDrawingPrimitives.cpp",
"cocos/2d/CCDrawingPrimitives.h",
"cocos/2d/CCFastTMXLayer.cpp",
"cocos/2d/CCFastTMXLayer.h",
"cocos/2d/CCFastTMXTiledMap.cpp",
"cocos/2d/CCFastTMXTiledMap.h",
"cocos/2d/CCFont.cpp",
"cocos/2d/CCFont.h",
"cocos/2d/CCFontAtlas.cpp",

View File

@ -170,6 +170,7 @@ Classes/Texture2dTest/Texture2dTest.cpp \
Classes/TextureCacheTest/TextureCacheTest.cpp \
Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp \
Classes/TileMapTest/TileMapTest.cpp \
Classes/TileMapTest/TileMapTest2.cpp \
Classes/TouchesTest/Ball.cpp \
Classes/TouchesTest/Paddle.cpp \
Classes/TouchesTest/TouchesTest.cpp \

View File

@ -163,6 +163,7 @@ set(SAMPLE_SRC
Classes/TexturePackerEncryptionTest/TextureAtlasEncryptionTest.cpp
Classes/TextureCacheTest/TextureCacheTest.cpp
Classes/TileMapTest/TileMapTest.cpp
Classes/TileMapTest/TileMapTest2.cpp
Classes/TouchesTest/Ball.cpp
Classes/TouchesTest/Paddle.cpp
Classes/TouchesTest/TouchesTest.cpp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,309 @@
#ifndef _TILEMAP_TEST_NEW_H_
#define _TILEMAP_TEST_NEW_H_
#include "../testBasic.h"
#include "../BaseTest.h"
class TileDemoNew : public BaseTest
{
public:
TileDemoNew(void);
virtual ~TileDemoNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
virtual void onExit()override;
void restartCallback(Ref* sender);
void nextCallback(Ref* sender);
void backCallback(Ref* sender);
void onTouchesMoved(const std::vector<Touch*>& touches, Event *event);
};
class TileMapTestNew : public TileDemoNew
{
public:
TileMapTestNew(void);
virtual std::string title() const override;
};
class TileMapEditTestNew : public TileDemoNew
{
public:
TileMapEditTestNew (void);
virtual std::string title() const override;
void updateMap(float dt);
};
class TMXOrthoTestNew : public TileDemoNew
{
public:
TMXOrthoTestNew(void);
virtual std::string title() const override;
virtual void onEnter() override;
virtual void onExit() override;
};
class TMXOrthoTest2New : public TileDemoNew
{
public:
TMXOrthoTest2New(void);
virtual std::string title() const override;
};
class TMXOrthoTest3New : public TileDemoNew
{
public:
TMXOrthoTest3New(void);
virtual std::string title() const override;
};
class TMXOrthoTest4New : public TileDemoNew
{
public:
TMXOrthoTest4New(void);
void removeSprite(float dt);
virtual std::string title() const override;
};
class TMXReadWriteTestNew : public TileDemoNew
{
unsigned int _gid;
unsigned int _gid2;
public:
TMXReadWriteTestNew(void);
virtual std::string title() const override;
void removeSprite(Node* sender);
void updateCol(float dt);
void repaintWithGID(float dt);
void removeTiles(float dt);
};
class TMXHexTestNew : public TileDemoNew
{
public:
TMXHexTestNew(void);
virtual std::string title() const override;
};
class TMXIsoTestNew : public TileDemoNew
{
public:
TMXIsoTestNew(void);
virtual std::string title() const override;
};
class TMXIsoTest1New : public TileDemoNew
{
public:
TMXIsoTest1New(void);
virtual std::string title() const override;
};
class TMXIsoTest2New : public TileDemoNew
{
public:
TMXIsoTest2New(void);
virtual std::string title() const override;
};
class TMXUncompressedTestNew : public TileDemoNew
{
public:
TMXUncompressedTestNew(void);
virtual std::string title() const override;
};
class TMXTilesetTestNew : public TileDemoNew
{
public:
TMXTilesetTestNew(void);
virtual std::string title() const override;
};
class TMXOrthoObjectsTestNew : public TileDemoNew
{
public:
TMXOrthoObjectsTestNew(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXIsoObjectsTestNew : public TileDemoNew
{
public:
TMXIsoObjectsTestNew(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXResizeTestNew : public TileDemoNew
{
public:
TMXResizeTestNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXIsoZorderNew : public TileDemoNew
{
Sprite* _tamara;
public:
TMXIsoZorderNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onExit(void);
~TMXIsoZorderNew();
void repositionSprite(float dt);
};
class TMXOrthoZorderNew : public TileDemoNew
{
Sprite* _tamara;
public:
TMXOrthoZorderNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual ~TMXOrthoZorderNew();
void repositionSprite(float dt);
};
class TMXIsoVertexZNew : public TileDemoNew
{
Sprite* _tamara;
public:
TMXIsoVertexZNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
~TMXIsoVertexZNew();
void repositionSprite(float dt);
virtual void onEnter() override;
virtual void onExit() override;
};
class TMXOrthoVertexZNew : public TileDemoNew
{
Sprite* _tamara;
public:
TMXOrthoVertexZNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
~TMXOrthoVertexZNew();
void repositionSprite(float dt);
virtual void onEnter() override;
virtual void onExit() override;
};
class TMXIsoMoveLayerNew : public TileDemoNew
{
public:
TMXIsoMoveLayerNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXOrthoMoveLayerNew : public TileDemoNew
{
public:
TMXOrthoMoveLayerNew(void);
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXTilePropertyTestNew : public TileDemoNew
{
public:
TMXTilePropertyTestNew();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXOrthoFlipTestNew : public TileDemoNew
{
public:
TMXOrthoFlipTestNew();
virtual std::string title() const override;
};
class TMXOrthoFlipRunTimeTestNew : public TileDemoNew
{
public:
TMXOrthoFlipRunTimeTestNew();
virtual std::string title() const override;
virtual std::string subtitle() const override;
void flipIt(float dt);
};
class TMXOrthoFromXMLTestNew : public TileDemoNew
{
public:
TMXOrthoFromXMLTestNew();
virtual std::string title() const override;
};
class TMXOrthoXMLFormatTestNew : public TileDemoNew
{
public:
TMXOrthoXMLFormatTestNew();
virtual std::string title() const override;
};
class TMXBug987New : public TileDemoNew
{
public:
TMXBug987New();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXBug787New : public TileDemoNew
{
public:
TMXBug787New();
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class TMXGIDObjectsTestNew : public TileDemoNew
{
public:
TMXGIDObjectsTestNew();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TileMapTestSceneNew : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -85,6 +85,7 @@ Controller g_aTestNames[] = {
{ "Node: Spine", []() { return new SpineTestScene(); } },
{ "Node: Sprite", [](){return new SpriteTestScene(); } },
{ "Node: TileMap", [](){return new TileMapTestScene(); } },
{ "Node: FastTileMap", [](){return new TileMapTestSceneNew(); } },
{ "Node: Text Input", [](){return new TextInputTestScene(); } },
{ "Node: UI", [](){ return new UITestScene(); }},
{ "Mouse", []() { return new MouseTestScene(); } },

View File

@ -22,6 +22,7 @@
#include "SceneTest/SceneTest.h"
#include "ParallaxTest/ParallaxTest.h"
#include "TileMapTest/TileMapTest.h"
#include "TileMapTest/TileMapTest2.h"
#include "IntervalTest/IntervalTest.h"
#include "LabelTest/LabelTest.h"
#include "LabelTest/LabelTestNew.h"

View File

@ -184,6 +184,7 @@
<ClCompile Include="..\Classes\SpineTest\SpineTest.cpp" />
<ClCompile Include="..\Classes\Sprite3DTest\Sprite3DTest.cpp" />
<ClCompile Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.cpp" />
<ClCompile Include="..\Classes\TileMapTest\TileMapTest2.cpp" />
<ClCompile Include="..\Classes\UITest\CocoStudioGUITest\CocosGUIScene.cpp" />
<ClCompile Include="..\Classes\UITest\CocoStudioGUITest\CocoStudioGUITest.cpp" />
<ClCompile Include="..\Classes\UITest\CocoStudioGUITest\CustomGUIScene.cpp" />
@ -366,6 +367,7 @@
<ClInclude Include="..\Classes\SpineTest\SpineTest.h" />
<ClInclude Include="..\Classes\Sprite3DTest\Sprite3DTest.h" />
<ClInclude Include="..\Classes\TexturePackerEncryptionTest\TextureAtlasEncryptionTest.h" />
<ClInclude Include="..\Classes\TileMapTest\TileMapTest2.h" />
<ClInclude Include="..\Classes\UITest\CocoStudioGUITest\CocosGUIScene.h" />
<ClInclude Include="..\Classes\UITest\CocoStudioGUITest\CocoStudioGUITest.h" />
<ClInclude Include="..\Classes\UITest\CocoStudioGUITest\CustomGUIScene.h" />

View File

@ -846,6 +846,9 @@
<ClCompile Include="..\Classes\ExtensionsTest\CocoStudioActionTimelineTest\ActionTimelineTestScene.cpp">
<Filter>Classes\ExtensionsTest\CocoStudioActionTimelineTest</Filter>
</ClCompile>
<ClCompile Include="..\Classes\TileMapTest\TileMapTest2.cpp">
<Filter>Classes\TileMapTest</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
@ -1562,5 +1565,8 @@
<ClInclude Include="..\Classes\ExtensionsTest\CocoStudioActionTimelineTest\ActionTimelineTestScene.h">
<Filter>Classes\ExtensionsTest\CocoStudioActionTimelineTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\TileMapTest\TileMapTest2.h">
<Filter>Classes\TileMapTest</Filter>
</ClInclude>
</ItemGroup>
</Project>