mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[cpp] Fix rotated region handling, EventData::volume default value.
This commit is contained in:
parent
d0d77b68ae
commit
45c60efd6a
@ -348,6 +348,13 @@ void Atlas::load(const char *begin, int length, const char *dir, bool createText
|
||||
// Calculate regionWidth/Height from UV coordinates
|
||||
region->_regionWidth = abs((int) ((region->_u2 - region->_u) * page->width));
|
||||
region->_regionHeight = abs((int) ((region->_v2 - region->_v) * page->height));
|
||||
|
||||
if (region->_degrees == 90) {
|
||||
int temp = region->_packedWidth;
|
||||
region->_packedWidth = region->_packedHeight;
|
||||
region->_packedHeight = temp;
|
||||
}
|
||||
|
||||
_regions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
using namespace spine;
|
||||
|
||||
EventData::EventData(const String &name) : _name(name), _intValue(0), _floatValue(0), _stringValue(), _audioPath(), _volume(1), _balance(0) {
|
||||
EventData::EventData(const String &name) : _name(name), _intValue(0), _floatValue(0), _stringValue(), _audioPath(), _volume(0), _balance(0) {
|
||||
assert(_name.length() > 0);
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ void MeshAttachment::updateRegion() {
|
||||
if (_uvs.size() != _regionUVs.size()) _uvs.setSize(_regionUVs.size(), 0);
|
||||
int n = (int) _regionUVs.size();
|
||||
float u, v, width, height;
|
||||
if (_region != nullptr && _region->rtti.instanceOf(AtlasRegion::rtti)) {
|
||||
if (_region != nullptr && _region->getRTTI().instanceOf(AtlasRegion::rtti)) {
|
||||
AtlasRegion *atlasRegion = static_cast<AtlasRegion *>(_region);
|
||||
u = _region->_u;
|
||||
v = _region->_v;
|
||||
@ -57,10 +57,12 @@ void MeshAttachment::updateRegion() {
|
||||
|
||||
switch (atlasRegion->_degrees) {
|
||||
case 90: {
|
||||
textureWidth = atlasRegion->_packedHeight / (_region->_u2 - _region->_u);
|
||||
textureHeight = atlasRegion->_packedWidth / (_region->_v2 - _region->_v);
|
||||
u -= (atlasRegion->_originalHeight - atlasRegion->_offsetY - atlasRegion->_packedHeight) / textureWidth;
|
||||
v -= (atlasRegion->_originalWidth - atlasRegion->_offsetX - atlasRegion->_packedWidth) / textureHeight;
|
||||
// Note: packed dimensions are swapped in Atlas.cpp for 90-degree regions
|
||||
// So we need to un-swap them here to get the original atlas dimensions
|
||||
textureWidth = atlasRegion->_packedWidth / (_region->_u2 - _region->_u);
|
||||
textureHeight = atlasRegion->_packedHeight / (_region->_v2 - _region->_v);
|
||||
u -= (atlasRegion->_originalHeight - atlasRegion->_offsetY - atlasRegion->_packedWidth) / textureWidth;
|
||||
v -= (atlasRegion->_originalWidth - atlasRegion->_offsetX - atlasRegion->_packedHeight) / textureHeight;
|
||||
width = atlasRegion->_originalHeight / textureWidth;
|
||||
height = atlasRegion->_originalWidth / textureHeight;
|
||||
for (int i = 0; i < n; i += 2) {
|
||||
|
||||
@ -68,7 +68,7 @@ void RegionAttachment::updateRegion() {
|
||||
bool rotated = false;
|
||||
AtlasRegion *atlasRegion = NULL;
|
||||
if (_region != NULL) {
|
||||
atlasRegion = _region->rtti.isExactly(AtlasRegion::rtti) ? static_cast<AtlasRegion *>(_region) : NULL;
|
||||
atlasRegion = _region->getRTTI().isExactly(AtlasRegion::rtti) ? static_cast<AtlasRegion *>(_region) : NULL;
|
||||
}
|
||||
if (atlasRegion) {
|
||||
localX += atlasRegion->_offsetX / atlasRegion->_originalWidth * width;
|
||||
|
||||
@ -1375,8 +1375,8 @@ Animation *SkeletonJson::readAnimation(Json *map, SkeletonData *skeletonData) {
|
||||
event->_floatValue = Json::getFloat(keyMap, "float", eventData->_floatValue);
|
||||
event->_stringValue = Json::getString(keyMap, "string", eventData->_stringValue.buffer());
|
||||
if (!eventData->_audioPath.isEmpty()) {
|
||||
event->_volume = Json::getFloat(keyMap, "volume", 1);
|
||||
event->_balance = Json::getFloat(keyMap, "balance", 0);
|
||||
event->_volume = Json::getFloat(keyMap, "volume", eventData->_volume);
|
||||
event->_balance = Json::getFloat(keyMap, "balance", eventData->_balance);
|
||||
}
|
||||
timeline->setFrame(frame, event);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user