무한 배경 스크롤이 완료되면 오브젝트가 고정되어 있습니다 (예 : 낙서 점프, Papi 점프의 Papy) 또는이 오브젝트가 실제로 움직입니다. 배경 이동 만합니다. 또는 두 가지 (배경과 개체) move.plz 누군가 나를 도울 수 있습니다. 나는이 솔루션을 4/5 일 동안 찾고 있지만 솔루션을 얻을 수 없습니다. 그래서 누군가가 나를 도와줍니다. 그리고 만약 물체가 물체가 움직이는 환상을 만드는 방법을 움직이지 않는다면.cocos2d에서 배경을 스크롤 할 때 객체가 고정되어 있습니까?
답변
개체를 스크롤하는 배경과 같은 레이어에 추가하면 배경 스크롤과 함께 스크롤됩니다.
당신이 낙서 점프에서 영웅과 같은 효과를 찾고 있다면 장면에 두 개 이상의 레이어가있는 것을 볼 수 있습니다.
- 계층 1 : 스크롤 배경 레이어
- 레이어 2 : 스프라이트 레이어
SomeScene.m
CCLayer *backgroundLayer = [[CCLayer alloc] init];
CCLayer *spriteLayer= [[CCLayer alloc] init];
[self addChild:backgroundLayer z:0];
[self addChild:spriteLayer z:1];
//Hero stays in one spot regardless of background scrolling.
CCSprite *squidHero = [[CCSprite alloc] initWithFile:@"squid.png"];
[spriteLayer addChild:squidHero];
당신이 객체가 배경에 추가 배경으로 스크롤하려면 층 :
//Platform moves with background.
CCSprite *bouncePlatform= [[CCSprite alloc] initWithFile:@"bouncePlatform.png"];
[backgroundLayer addChild:bouncePlatform];
또 다른 대안은 CCFollow 작업을 사용하는 것입니다. 배경이 정적 인 것처럼 코딩하고 플레이어가 움직이는 것처럼 코딩하고 플레이어에 CCFollow 액션을 추가합니다. 이것은 기본적으로 카메라를 움직여 플레이어를 추적합니다.
오프셋을 따르도록 (즉, 플레이어가 화면 중앙에 있지 않도록) CCFollow 동작을 수행 할 수 있도록 클래스를 수정하고 스무딩 효과를 줄 수도 있습니다. 플레이어가 움직이면 팔로우 액션이 번지지 않게됩니다. 아래 코드를 참조하십시오 :
* 참고 cocos2d-x, C++ 포트를 사용하고 있습니다. 이 메소드는 cocos2d에서 유사하며 cocos2d 구문에 맞게이 메소드를 수정할 수 있어야합니다. 또는 주위를 검색 - 내가 cocos2d에 대한 이들을 발견하고 C로 포팅 + +.
//defines the action to constantly follow the player (in my case, "runner.p_sprite is the sprite pointing to the player)
FollowWithOffset* followAction = FollowWithOffset::create(runner.p_sprite, CCRectZero);
runAction(followAction);
그리고 CCFollow 내 자신의 클래스, CCFollowWithAction을 만들 별도로, 나는 클래스 정의를 복사 한. 이것은 또한 플레이어가 움직일 때, 동작이 덜컹 거리지 않도록 부드럽게하는 효과 (더 온라인으로 볼 수 있습니다)가 있습니다. "initWithTarget"을 수정하여 오프셋을 고려하고 "단계"를 사용하여 스무딩 작업을 추가했습니다. 아래 주석에서 수정 내용을 볼 수 있습니다.
bool FollowWithOffset::initWithTarget(CCNode *pFollowedNode, const CCRect& rect/* = CCRectZero*/)
{
CCAssert(pFollowedNode != NULL, "");
pFollowedNode->retain();
m_pobFollowedNode = pFollowedNode;
if (rect.equals(CCRectZero))
{
m_bBoundarySet = false;
}
else
{
m_bBoundarySet = true;
}
m_bBoundaryFullyCovered = false;
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
m_obFullScreenSize = CCPointMake(winSize.width, winSize.height);
//m_obHalfScreenSize = ccpMult(m_obFullScreenSize, 0.5f);
m_obHalfScreenSize = CCPointMake(m_obFullScreenSize.x/2 + RUNNER_FOLLOW_OFFSET_X,
m_obFullScreenSize.y/2 + RUNNER_FOLLOW_OFFSET_Y);
if (m_bBoundarySet)
{
m_fLeftBoundary = -((rect.origin.x+rect.size.width) - m_obFullScreenSize.x);
m_fRightBoundary = -rect.origin.x ;
m_fTopBoundary = -rect.origin.y;
m_fBottomBoundary = -((rect.origin.y+rect.size.height) - m_obFullScreenSize.y);
if(m_fRightBoundary < m_fLeftBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary)/2;
}
if(m_fTopBoundary < m_fBottomBoundary)
{
// screen width is larger than world's boundary width
//set both in the middle of the world
m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary)/2;
}
if((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary))
{
m_bBoundaryFullyCovered = true;
}
}
return true;
}
void FollowWithOffset::step(float dt)
{
CC_UNUSED_PARAM(dt);
if(m_bBoundarySet){
// whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
if(m_bBoundaryFullyCovered)
return;
CCPoint tempPos = ccpSub(m_obHalfScreenSize, m_pobFollowedNode->getPosition());
m_pTarget->setPosition(ccp(clampf(tempPos.x, m_fLeftBoundary, m_fRightBoundary),
clampf(tempPos.y, m_fBottomBoundary, m_fTopBoundary)));
}
else{
//custom written code to add in support for a smooth ccfollow action
CCPoint tempPos = ccpSub(m_obHalfScreenSize, m_pobFollowedNode->getPosition());
CCPoint moveVect = ccpMult(ccpSub(tempPos,m_pTarget->getPosition()),0.25); //0.25 is the smooth constant.
CCPoint newPos = ccpAdd(m_pTarget->getPosition(), moveVect);
m_pTarget->setPosition(newPos);
}
}
- 1. 선택된 UITableViewCell이 스크롤 할 때 배경을 변경합니다.
- 2. 스크롤 할 때 게시물의 제목은 항상 고정되어 있습니다.
- 3. 가로로 스크롤 할 때 div 배경을 숨기는 것을 피하는 방법
- 4. jquery에서 아래로 스크롤 할 때 스크롤 할 때 뭔가를 수행하십시오.
- 5. 스크롤 할 때 뒤처짐
- 6. 아래로 스크롤 할 때 스크롤 위치입니다. jquery
- 7. div에서 스크롤 할 때 스크롤 페이지
- 8. 스크롤 할 때 콘텐츠를 수정하는 Jquery 플러그인이 있습니까?
- 9. 스크롤 할 때 텍스트 페이드 아웃
- 10. 스크롤 할 때 고정 요소
- 11. 정적 멤버가 이동 가능하거나 고정되어 있습니까?
- 12. cocos2d에서 CCLayer를 이동하는 방법
- 13. cocos2d에서 정지 효과가 있습니까?
- 14. 스크롤 할 때 viewForHeaderInSection이 사라집니다.
- 15. 사용자가 스크롤 할 때 콘텐츠로드
- 16. 스크롤 할 때 UITableView가 충돌합니다.
- 17. 어떻게 안드로이드 게임을위한 스크롤 가능한 배경을 그려야합니까?
- 18. cocos2d에서 애니메이션 추가
- 19. RDLC 보고서에서 직사각형의 높이가 고정되어 있습니까?
- 20. jQuery UI 모달 대화 상자가 스크롤 할 때 고정되어야 함
- 21. 배열은 ASP.NET 2.0에서 실제로 길이가 고정되어 있습니까?
- 22. 사용자가 cocos2d에서 화면을 터치 할 때 몸체를 회전시킬 수있는 방법
- 23. Java에서 regex는 기본적으로^및 $ 문자로 고정되어 있습니까?
- 24. 스크롤 할 때 일정한 픽셀을 통과 할 때 위치가 고정되었습니다.
- 25. cocos2d에서 UIPickerView를 사용할 수 있습니까?
- 26. 장고 캐싱이 왜 django.views.static.serve로 고정되어 있습니까?
- 27. 스크롤 할 때 UITableViewCell이 반복적으로 할당 됨
- 28. 스크롤 할 때 가운데에있는 div 변경 위치
- 29. Scrollview에서 Scrollview를 가로로 스크롤 할 때
- 30. 스크롤 할 때 "고정"요소 만들기
좋아, - 고마워 내가 어떻게 같은 time.So에서이 2 개의 레이어를 실행하는 낙서와 platform.which 사이의 충돌을 알아 내기 위해 다른 이시군요을하는이이 2 개의 다른 layer.Because를 동기화하는 방법 지금까지 단 하나의 레이어 만 사용 했으므로 2 개의 레이어를 함께 실행하고 충돌을 확인하는 방법. – russell