diff --git a/cocos/2d/CCActionTiledGrid.cpp b/cocos/2d/CCActionTiledGrid.cpp index 3faae36bd8..3e624729f2 100644 --- a/cocos/2d/CCActionTiledGrid.cpp +++ b/cocos/2d/CCActionTiledGrid.cpp @@ -243,11 +243,11 @@ void ShuffleTiles::shuffle(unsigned int *array, unsigned int len) Size ShuffleTiles::getDelta(const Size& pos) const { unsigned int idx = static_cast(pos.width * _gridSize.height + pos.height); + Vec2 pos2; + pos2.x = (float)(_tilesOrder[idx] / (int)_gridSize.height); + pos2.y = (float)(_tilesOrder[idx] % (int)_gridSize.height); - float x = _tilesOrder[idx] / (_gridSize.height - pos.width); - float y = (float)(_tilesOrder[idx] % (int)(_gridSize.height - pos.height)); - - return Size(x, y); + return Size((int)(pos2.x - pos.width), (int)(pos2.y - pos.height)); } void ShuffleTiles::placeTile(const Vec2& pos, Tile *t) diff --git a/cocos/2d/CCGrid.cpp b/cocos/2d/CCGrid.cpp index c63b10fa9d..3517a0b3a1 100644 --- a/cocos/2d/CCGrid.cpp +++ b/cocos/2d/CCGrid.cpp @@ -811,7 +811,7 @@ void TiledGrid3D::updateVertexAndTexCoordinate() memcpy((char*)_vertexBuffer + offset, &tempVecPointer[i], sizeof(Vec3)); memcpy((char*)_vertexBuffer + offset + sizeof(Vec3), &tempTexPointer[i], sizeof(Vec2)); } - _drawCommand.createVertexBuffer((unsigned int)(sizeof(Vec3) + sizeof(Vec2) ), numOfPoints, CustomCommand::BufferUsage::DYNAMIC); + _drawCommand.createVertexBuffer((sizeof(Vec3) + sizeof(Vec2) ), numOfPoints, CustomCommand::BufferUsage::DYNAMIC); _drawCommand.updateVertexBuffer(_vertexBuffer, numOfPoints * sizeof(Vec3) + numOfPoints * sizeof(Vec2)); _drawCommand.createIndexBuffer(CustomCommand::IndexFormat::U_SHORT, gradSize * 6, CustomCommand::BufferUsage::DYNAMIC);