bool PlayLayer::onTouchBegan(Touch *touch, Event *unused_event) { if (m_isTouchEnable) { SushiSprite *sushi = nullptr; for (int i = 0; i < m_width*m_height; i++) { sushi = m_matrix[i]; if (sushi) { //将触点坐标, 转换为相对节点sushi的, 相对坐标 auto point = sushi->convertTouchToNodeSpace(touch); //构造sushi的尺寸矩形 Size size = sushi->getContentSize(); Rect rect = Rect(0, 0, size.width, size.height); //判断触点是否触摸到sp内部 if (rect.containsPoint(point)) { m_srcSushi = sushi; } } } } checkAndRemoveChain(); return m_isTouchEnable; }
void GameLayer::update(float dt) { // check if animationing if (m_isAnimationing) { // init with false m_isAnimationing = false; for (int i = 0; i < m_height * m_width; i++) { Monster *mon = m_matrix[i]; if (mon && mon->getNumberOfRunningActions() > 0) { m_isAnimationing = true; break; } } } // if Monter is moving, ignore use touch event m_isTouchEnable = !m_isAnimationing; if (!m_isAnimationing) { if (m_isNeedFillVacancies) { //爆炸效果结束后才掉落新怪物,增强打击感 fillVacancies(); m_isNeedFillVacancies = false; } else { checkAndRemoveChain(); } } }
void BallMap::update(float dt) { // check if animationing if (m_isAnimationing) { // init with false m_isAnimationing = false; for (int i = 0; i < m_size.height * m_size.width; i++) { BallSprite *ball = m_matrix[i]; if (ball && ball->get_isMoving()) { m_isAnimationing = true; break; } } } // if Ball is moving, ignore use touch event m_isTouchEnable = !m_isAnimationing; if (!m_isAnimationing) { if (m_isNeedFillVacancies) { //爆炸效果结束后才掉落新寿司,增强打击感 fillVacancies(); m_isNeedFillVacancies = false; } else { if (m_isNeedCheckSelf) { checkAndRemoveChain(); } } } }
void PlayLayer::update(float dt) { // Kiểm tra giá trị lần đầu của m_isAnimationing, mỗi bước thời gian dt, sẽ lại kiểm tra m_isAnimationing là true hay flase if (m_isAnimationing) { // nếu True // Gán = false m_isAnimationing = false; // Duyệt trong toàn ma trận for (int i = 0; i < m_height * m_width; i++) { SushiSprite *sushi = m_matrix[i]; // Nếu tồn tại 1 Sushi mà đang có "Action" thì m_isAnimationing = true, và thoát vòng lặp if (sushi && sushi->getNumberOfRunningActions() > 0) { m_isAnimationing = true; break; } } } // Đến khi không có Action nào của Sushi tại bước thời gian dt nào đó, thì kiểm tra việc "Ăn" dãy Sushi nếu tồn tại // Thiết lập cờ cho phép Touch khi không còn chuyển động, và ngược lại m_isTouchEnable = !m_isAnimationing; //Nếu ko có chuyển động if (!m_isAnimationing) { // Xét xem phải điền đầy ô trống không if (m_isNeedFillVacancies) { fillVacancies(); // điền đầy m_isNeedFillVacancies = false; } else { checkAndRemoveChain(); // Kiểm tra và ăn các chuỗi } } }