void Sprite::setFlippedX(bool flippedX) { if (flippedX != isFlippedX()) { _frame.flipX(); _flags ^= flag_flipX; animFrameChanged(_frame); } }
void Fire::updateBodyBox(){ Vec2 origin = m_bodyBox.origin.origin; Size size = m_bodyBox.origin.size; if (isFlippedX()){ m_bodyBox.actual = Rect(origin.x + getPositionX(), origin.y + getPositionY(), size.width, size.height); } else{ m_bodyBox.actual = Rect(getContentSize().width - origin.x - size.width + getPositionX(), origin.y + getPositionY(), size.width, size.height); } }
eAction SheepStandingState::getDirection(Sheep *sheep) { auto action = eAction::NONE; auto sprite = dynamic_cast<LHSprite*>(sheep->getChildNodeWithName(sheepDefs::SPRITE_NAME)); if (sprite) { action = (sprite->isFlippedX()) ? eAction::MOVE_LEFT : eAction::MOVE_RIGHT; } return action; }
void Fire::update(float dt){ if (m_velocity.x == 0){ return; } if (isFlippedX()){ setPosition(getPosition() + m_velocity); } else{ setPosition(getPosition() - m_velocity); } updateBodyBox(); checkEnemy(); ++m_nTimer; if (m_nTimer > 30){ runAction(m_endAction); } }
void Sprite::serialize(serializedata* data) { inherited::serialize(data); pugi::xml_node node = data->node; const ResAnim* rs = getResAnim(); if (rs) { node.remove_attribute("size"); Resource* r = rs->getParent(); const char* hint = ""; if (r) { r = r->getParent(); if (r) hint = r->getName().c_str(); } if (rs->getName().find(':') == std::string::npos) { char name[255]; safe_sprintf(name, "%s:%s", hint, rs->getName().c_str()); node.append_attribute("resanim").set_value(name); } else { node.append_attribute("resanim").set_value(rs->getName().c_str()); } if (_frame.getColumn() != 0) node.append_attribute("column").set_value(_frame.getColumn()); if (_frame.getRow() != 0) node.append_attribute("row").set_value(_frame.getRow()); } setAttr(node, "flipX", isFlippedX(), false); setAttr(node, "flipY", isFlippedY(), false); node.set_name("Sprite"); }
void Sprite::setFlipped(bool flippedX, bool flippedY) { bool fx = flippedX != isFlippedX(); bool fy = flippedY != isFlippedY(); if (fx) { _frame.flipX(); _flags ^= flag_flipX; } if (fy) { _frame.flipY(); _flags ^= flag_flipY; } if (fx || fy) animFrameChanged(_frame); }
void GAFObject::realizeFrame(cocos2d::Node* out, uint32_t frameIndex) { const AnimationFrames_t& animationFrames = m_timeline->getAnimationFrames(); if (animationFrames.size() <= frameIndex) { return; } GAFAnimationFrame *currentFrame = animationFrames[frameIndex]; const GAFAnimationFrame::SubobjectStates_t& states = currentFrame->getObjectStates(); for (const GAFSubobjectState* state : states) { GAFObject* subObject = m_displayList[state->objectIdRef]; CCASSERT(subObject, "Error. SubObject with current ID not found"); if (!subObject) continue; if (state->colorMults()[GAFColorTransformIndex::GAFCTI_A] >= 0.f && subObject->m_isInResetState) { subObject->m_currentFrame = subObject->m_currentSequenceStart; } subObject->m_isInResetState = state->colorMults()[GAFColorTransformIndex::GAFCTI_A] < 0.f; if (!state->isVisible()) continue; if (subObject->m_charType == GAFCharacterType::Timeline) { if (!subObject->m_isInResetState) { cocos2d::AffineTransform stateTransform = state->affineTransform; float csf = m_timeline->usedAtlasScale(); stateTransform.tx *= csf; stateTransform.ty *= csf; cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform); subObject->setAdditionalTransform(t); subObject->m_parentFilters.clear(); const Filters_t& filters = state->getFilters(); subObject->m_parentFilters.insert(subObject->m_parentFilters.end(), filters.begin(), filters.end()); const float* cm = state->colorMults(); subObject->m_parentColorTransforms[0] = cocos2d::Vec4( m_parentColorTransforms[0].x * cm[0], m_parentColorTransforms[0].y * cm[1], m_parentColorTransforms[0].z * cm[2], m_parentColorTransforms[0].w * cm[3]); subObject->m_parentColorTransforms[1] = cocos2d::Vec4(state->colorOffsets()) + m_parentColorTransforms[1]; if (m_masks[state->objectIdRef]) { rearrangeSubobject(out, m_masks[state->objectIdRef], state->zIndex); } else { //subObject->removeFromParentAndCleanup(false); if (state->maskObjectIdRef == IDNONE) { rearrangeSubobject(out, subObject, state->zIndex); } else { // If the state has a mask, then attach it // to the clipping node. Clipping node will be attached on its state auto mask = m_masks[state->maskObjectIdRef]; CCASSERT(mask, "Error. No mask found for this ID"); if (mask) rearrangeSubobject(mask, subObject, state->zIndex); } } subObject->step(); } } else if (subObject->m_charType == GAFCharacterType::Texture) { cocos2d::Vect prevAP = subObject->getAnchorPoint(); cocos2d::Size prevCS = subObject->getContentSize(); #if ENABLE_RUNTIME_FILTERS if (subObject->m_objectType == GAFObjectType::MovieClip) { // Validate sprite type (w/ or w/o filter) const Filters_t& filters = state->getFilters(); GAFFilterData* filter = NULL; GAFMovieClip* mc = static_cast<GAFMovieClip*>(subObject); if (m_parentFilters.size() > 0) { filter = *m_parentFilters.begin(); } else if (filters.size() > 0) { filter = *filters.begin(); } if (filter) { filter->apply(mc); } if (!filter || filter->getType() != GAFFilterType::GFT_Blur) { mc->setBlurFilterData(nullptr); } if (!filter || filter->getType() != GAFFilterType::GFT_ColorMatrix) { mc->setColorMarixFilterData(nullptr); } if (!filter || filter->getType() != GAFFilterType::GFT_Glow) { mc->setGlowFilterData(nullptr); } if (!filter || filter->getType() != GAFFilterType::GFT_DropShadow) { GAFDropShadowFilterData::reset(mc); } } #endif cocos2d::Size newCS = subObject->getContentSize(); cocos2d::Vect newAP = cocos2d::Vect(((prevAP.x - 0.5f) * prevCS.width) / newCS.width + 0.5f, ((prevAP.y - 0.5f) * prevCS.height) / newCS.height + 0.5f); subObject->setAnchorPoint(newAP); if (m_masks[state->objectIdRef]) { rearrangeSubobject(out, m_masks[state->objectIdRef], state->zIndex); } else { //subObject->removeFromParentAndCleanup(false); if (state->maskObjectIdRef == IDNONE) { rearrangeSubobject(out, subObject, state->zIndex); } else { // If the state has a mask, then attach it // to the clipping node. Clipping node will be attached on its state auto mask = m_masks[state->maskObjectIdRef]; CCASSERT(mask, "Error. No mask found for this ID"); if (mask) rearrangeSubobject(mask, subObject, state->zIndex); } } cocos2d::AffineTransform stateTransform = state->affineTransform; float csf = m_timeline->usedAtlasScale(); stateTransform.tx *= csf; stateTransform.ty *= csf; cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform); if (isFlippedX() || isFlippedY()) { float flipMulX = isFlippedX() ? -1 : 1; float flipOffsetX = isFlippedX() ? getContentSize().width - m_asset->getHeader().frameSize.getMinX() : 0; float flipMulY = isFlippedY() ? -1 : 1; float flipOffsetY = isFlippedY() ? -getContentSize().height + m_asset->getHeader().frameSize.getMinY() : 0; cocos2d::AffineTransform flipCenterTransform = cocos2d::AffineTransformMake(flipMulX, 0, 0, flipMulY, flipOffsetX, flipOffsetY); t = AffineTransformConcat(t, flipCenterTransform); } subObject->setExternalTransform(t); if (subObject->m_objectType == GAFObjectType::MovieClip) { GAFMovieClip* mc = static_cast<GAFMovieClip*>(subObject); float colorMults[4] = { state->colorMults()[0] * m_parentColorTransforms[0].x, state->colorMults()[1] * m_parentColorTransforms[0].y, state->colorMults()[2] * m_parentColorTransforms[0].z, state->colorMults()[3] * m_parentColorTransforms[0].w }; float colorOffsets[4] = { state->colorOffsets()[0] + m_parentColorTransforms[1].x, state->colorOffsets()[1] + m_parentColorTransforms[1].y, state->colorOffsets()[2] + m_parentColorTransforms[1].z, state->colorOffsets()[3] + m_parentColorTransforms[1].w }; mc->setColorTransform(colorMults, colorOffsets); } } else if (subObject->m_charType == GAFCharacterType::TextField) { GAFTextField *tf = static_cast<GAFTextField*>(subObject); rearrangeSubobject(out, subObject, state->zIndex); cocos2d::AffineTransform stateTransform = state->affineTransform; float csf = m_timeline->usedAtlasScale(); stateTransform.tx *= csf; stateTransform.ty *= csf; cocos2d::AffineTransform t = GAF_CGAffineTransformCocosFormatFromFlashFormat(state->affineTransform); if (isFlippedX() || isFlippedY()) { float flipMulX = isFlippedX() ? -1 : 1; float flipOffsetX = isFlippedX() ? getContentSize().width - m_asset->getHeader().frameSize.getMinX() : 0; float flipMulY = isFlippedY() ? -1 : 1; float flipOffsetY = isFlippedY() ? -getContentSize().height + m_asset->getHeader().frameSize.getMinY() : 0; cocos2d::AffineTransform flipCenterTransform = cocos2d::AffineTransformMake(flipMulX, 0, 0, flipMulY, flipOffsetX, flipOffsetY); t = AffineTransformConcat(t, flipCenterTransform); } subObject->setExternalTransform(t); } if (state->isVisible()) { subObject->m_lastVisibleInFrame = frameIndex + 1; } } GAFAnimationFrame::TimelineActions_t timelineActions = currentFrame->getTimelineActions(); for (GAFTimelineAction action : timelineActions) { switch (action.getType()) { case GAFActionType::Stop: pauseAnimation(); break; case GAFActionType::Play: resumeAnimation(); break; case GAFActionType::GotoAndStop: gotoAndStop(action.getParam(GAFTimelineAction::PI_FRAME)); break; case GAFActionType::GotoAndPlay: gotoAndPlay(action.getParam(GAFTimelineAction::PI_FRAME)); break; case GAFActionType::DispatchEvent: _eventDispatcher->dispatchCustomEvent(action.getParam(GAFTimelineAction::PI_EVENT_TYPE), &action); break; case GAFActionType::None: default: break; } } }