| 217 | } |
| 218 | |
| 219 | SpriteVisual::SpriteVisual(String filename) |
| 220 | : _isAutoRemoved(false) |
| 221 | , _sprite(nullptr) |
| 222 | , _action(nullptr) { |
| 223 | if (FrameActionDef* frameActionDef = SharedFrameCache.loadFrame(filename)) { |
| 224 | if (Texture2D* tex = SharedTextureCache.load(frameActionDef->clipStr)) { |
| 225 | _sprite = Sprite::create(tex, *frameActionDef->rects[0]); |
| 226 | Action* action = Action::create(FrameAction::alloc(frameActionDef)); |
| 227 | WRef<SpriteVisual> self{this}; |
| 228 | _sprite->slot("ActionEnd"_slice, [self, action](Event* event) { |
| 229 | Action* eventAction = nullptr; |
| 230 | Node* target = nullptr; |
| 231 | if (event->get(eventAction, target) && action == eventAction) { |
| 232 | if (self) { |
| 233 | self->_sprite->setVisible(false); |
| 234 | if (self->_isAutoRemoved) { |
| 235 | self->removeFromParent(true); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | }); |
| 240 | _action = action; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | bool SpriteVisual::init() { |
| 246 | if (!Visual::init()) return false; |
nothing calls this directly
no test coverage detected