| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dbase.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							|  |  |  |  | #include "..\e2dmanager.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Scene::Scene() | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	: _autoUpdate(true) | 
					
						
							| 
									
										
										
										
											2018-05-15 23:59:58 +08:00
										 |  |  |  | 	, _root(nullptr) | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-06 12:59:32 +08:00
										 |  |  |  | 	_root = new (e2d::autorelease) Node(); | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	GC::retain(_root); | 
					
						
							| 
									
										
										
										
											2018-07-06 00:47:50 +08:00
										 |  |  |  | 	_root->_setParentScene(this); | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Scene::~Scene() | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	GC::safeRelease(_root); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Scene::_render() | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_root->_render(); | 
					
						
							| 
									
										
										
										
											2017-10-29 23:48:32 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 11:00:41 +08:00
										 |  |  |  | 	if (Game::getInstance()->getConfig()->isColliderVisible()) | 
					
						
							| 
									
										
										
										
											2017-10-29 23:48:32 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-16 15:49:48 +08:00
										 |  |  |  | 		// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							| 
									
										
										
										
											2017-12-16 15:49:48 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD>ͼ<EFBFBD><CDBC>
 | 
					
						
							| 
									
										
										
										
											2018-07-07 15:12:18 +08:00
										 |  |  |  | 		_root->_renderCollider(); | 
					
						
							| 
									
										
										
										
											2017-10-29 23:48:32 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Scene::_update() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-06 21:11:54 +08:00
										 |  |  |  | 	// ִ<><D6B4> onUpdate <20><><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	if (_autoUpdate) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-02-06 21:11:54 +08:00
										 |  |  |  | 		this->onUpdate(); | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-06 21:11:54 +08:00
										 |  |  |  | 	// <20><><EFBFBD>¸<EFBFBD><C2B8>ڵ<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_root->_update(); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Scene::setAutoUpdate(bool bAutoUpdate) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_autoUpdate = bAutoUpdate; | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 11:46:57 +08:00
										 |  |  |  | void e2d::Scene::add(Node * child, int order /* = 0 */) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_root->addChild(child, order); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 17:02:18 +08:00
										 |  |  |  | void e2d::Scene::add(const std::vector<Node*>& nodes, int order) | 
					
						
							| 
									
										
										
										
											2018-04-01 00:04:33 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 17:02:18 +08:00
										 |  |  |  | 	for (auto node : nodes) | 
					
						
							| 
									
										
										
										
											2018-04-01 00:04:33 +08:00
										 |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		this->add(node, order); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | bool e2d::Scene::remove(Node * child) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _root->removeChild(child); | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | std::vector<e2d::Node*> e2d::Scene::get(const String& name) const | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _root->getChildren(name); | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-07 15:48:06 +08:00
										 |  |  |  | e2d::Node * e2d::Scene::getOne(const String& name) const | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _root->getChild(name); | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 14:16:36 +08:00
										 |  |  |  | const std::vector<e2d::Node*>& e2d::Scene::getAll() const | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _root->getAllChildren(); | 
					
						
							| 
									
										
										
										
											2018-04-24 13:28:21 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Node * e2d::Scene::getRoot() const | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _root; | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | } |