Post

반응형

Rect

Rect로 범위를 지정하여 이미지에서 보여주고 싶은 부분만 보여줄 수 있다.

auto sprite = Sprite::create("HelloWorld.png", Rect(0, 0, 100, 150));

0, 0 좌표에서 너비 100, 높이 150만큼만 이미지를 가져온다.

그러면 아래처럼 너비 100에 높이 150인 이미지가 그려진 것을 확인할 수 있다.

그리고 그림으로 확인해보니 좌표계가 왼상단이 0,0이 되고 아래로 그림을 그려준다.

이는 cocos2d-x 좌표계와 다르니 유념할 것.

Scale

이미지의 크기를 키울 수 있다.

sprite->setScale(4.0);
sprite->setScaleX(2.0);
sprite->setScaleY(0.5);

setScale(4.0): 그림을 4배 키운다.
setScaleX(2.0): X축만 2배 키운다.
setScaleY(0.5): Y축만 절반으로 줄인다.

Rect처럼 일정 부분을 보여주는 게 아니라서

그림이 짜부라지거나 치즈처럼 늘어나는 그림이 보여지게 된다.

반응형

Rotation

sprite->setRotation(90);
sprite->setRotationSkewX(10);
sprite->setRotationSkewY(10);

setRotation(90): Z축을 중심으로 90도 회전. 우리가 일반적으로 알고있는 시계방향, 반시계 방향 회전이다.
setRotationSkewX(10): X축을 중심으로 10도 회전. Y축은 회전하지 않고 X축만 회전한다고 생각하면 된다. 
setRotationSkewY(10): Y축을 중심으로 10도 회전. X축은 회전하지 않고 Y축만 회전한다고 생각하면 된다. 

Flipe

sprite->setFlippedX(true);
sprite->setFlippedY(true);

상하좌우를 뒤집는 함수입니다.

setFlippedX(true): X축을 기준으로 좌우를 뒤집습니다. 
setFlippedY(true): Y축을 기준으로 상하로 뒤집습니다.

Opacity

sprite->setOpacity(40);

이미지의 불투명도를 조절한다. 0~255까지 값이 가능하다.

Visible

sprite->setVisible(false);

  setVisible(false): 화면에 보일 것 인지 보이지 않을 것인지 true, false로 셋팅한다.

Color

sprite->setColor(Color3B(255, 150, 150));

setColor로 R,G,B값을 0~255까지 줘서 이미지에 색을 입힐 수 있다.

반응형

Post

반응형

cocos2d github에서 cpp-tests 폴더 안에 있는 샘플들은 공부하는데 꽤나 유용해보였다.

그래서 이 샘플 가지고 공부를 하기로 결정!

cocos2d github cpp-tests 프로젝트 빌드 파일 실행하기

cocos2d-x-4\cocos2d-x-4\tests

다운받은 코코스 파일 안에 테스트 파일 있는 거 확인(tests폴더)

그래서 해당 프젝을 옮겨서 cmake로 빌드 파일 만들려고 하니까 에러가 난다.

H:\CocosProject\cpp-tests\build>cmake . -G "Visual Studio 17 2022" -A Win32
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
CMake Error at CMakeLists.txt:17 (include):
  include could not find requested file:

    CocosBuildSet


CMake Error at CMakeLists.txt:18 (add_subdirectory):
  add_subdirectory given source "H:/CocosProject/cpp-tests/../../cocos" which
  is not an existing directory.


CMake Error at CMakeLists.txt:403 (setup_cocos_app_config):
  Unknown CMake command "setup_cocos_app_config".


-- Configuring incomplete, errors occurred!

H:\CocosProject\cpp-tests\build>

관련해서 검색해보니까 같은 이슈 발견

https://github.com/cocos2d/cocos2d-x/issues/18696

 

Missing Cmake references · Issue #18696 · cocos2d/cocos2d-x

Hi! I'm trying to build a cocos2d-x3.17 project on Ubuntu 16.04. What I did: > git clone --recursive https://github.com/cocos2d/cocos2d-x. > cd cocos2d- > python download-deps. > git submodule upda...

github.com

반응형

Modules 에 있는 CocosBuildSet.cmake를 복사하라고 한다.

일단 기본프로젝트는 실행이 잘되어서 기본프젝에서 cocosBuildSet 위치를 검색해봤더니

test(프젝)\cocos2d\cmake\Modules에 존재한다.

\test\cocos2d 폴더를 통째로 cpp-tests 폴더에 복사했다.

근데 안된다. 그래서 빌드되는 프로젝트 CMakeLists.txt 와 안되는 프로젝트 CMakeLists.txt의 차이점을 비교함.

cocosBuildSet를 못찾는 거 보니 둘의 기본 경로가 다른 거 같음.

그리고 역시나 경로가 달랐음.

test프로젝트: set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d)

cpp test 프로젝트: set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)

그래서 CMakeLists 복사본 만들고 위치를 test프로젝트처럼 수정.

그러니까 sln 프로젝트 파일 만들어짐!!!! 성공 ㅠㅠㅠㅠㅠㅠ

근데 빌드하니까 에러 발생...

그런데 에러들을 보니까...함수 인자 갯수가 맞지 않는다고 하는 걸 보니

이거 설마 최근 함수 적용이 안된건가 싶다;;;끄으응;;;;

이 프로젝트는 그래도 simple sample이 많은 거 같아서 꼭 돌려보고 싶었는데...;;;;

전부 최신화 시켜줘야 돌아가는건가 싶다;; 일단 보니까 빌드 실패해서 exe파일도 bin 폴더에 안만들어져있음.

(수정중)

일단 에러 하나하나 뜯어보기로 했음

에러 목록

1. 'spine/Debug.h'


오류 C1083 포함 파일을 열 수 없습니다. 'spine/Debug.h': No such file or directory

 일단 쓰는 곳이 없어서 주석 처리.

Label::createWithBMFont("fonts/geneva-32.fnt", "And this is Geneva", TextHAlignment::LEFT, 0, Rect(0, 128, 0, 0));

일단 createWithBMFont 함수 레퍼런스 찾아봄.

https://docs.cocos2d-x.org/api-ref/cplusplus/v4x/db/de4/classcocos2d_1_1_label.html#ab9d3a60682e0d77312e2f154a2840647

 

Cocos2d-x: Label Class Reference

Label is a subclass of Node that knows how to render text labels. More... Inherits Node, LabelProtocol, and BlendProtocol. Inherited by TextFieldTTF. virtual void setString (const std::string &text) override  Sets the text that this Label is to display.

docs.cocos2d-x.org

static Label* createWithBMFont ( const std::string &  bmfontPath,
    const std::string &  text,
    const TextHAlignment  hAlignment = TextHAlignment::LEFT,
    int  maxLineWidth = 0,
    const Vec2  imageOffset = Vec2::ZERO 
  )

Allocates and initializes a Label, with a bitmap font file.

Parameters

bmfontPath A bitmap font file, it's a FNT format.
text The initial text.
hAlignment Text horizontal alignment.
maxLineWidth The max line width.
imageOffset  

ReturnsAn automatically released Label object.See alsosetBMFontFilePath setMaxLineWidth

 

Cocos2d-x: Label Class Reference

Label is a subclass of Node that knows how to render text labels. More... Inherits Node, LabelProtocol, and BlendProtocol. Inherited by TextFieldTTF. virtual void setString (const std::string &text) override  Sets the text that this Label is to display.

docs.cocos2d-x.org

5개 인자라서 false 빼주고 rect 대신 vector 해줌. 어차피 밑에서 벡터 set해주길래 그냥 0, 0으로 넣음. 그리고 어차피 실행이 목적이라 아무 값이나 넣거나 주석 처리 ㄱㄱ

auto label2 = Label::createWithBMFont("fonts/geneva-32.fnt", "And this is Geneva", TextHAlignment::LEFT, 0, Vec2(0, 0));

그랬더니 오류 133개가 튀어나왔다 아...........

으앙...더해보고 안되면 뭐 레퍼런스나 다른 프로젝트 참고를 해야겠어ㅠㅠ

근데 일단 에러나는 파일을 보면

SpineTest.h

SpineTest.cpp

CCConsole.h

ccUTF8.h

이 4개라서 이걸 제외하기로 결정. 일단 CCConsole.h, ccUTF8.h는 하나씩만 에러가 나고

몇백개 대부분 에러는 SpineTest.h, SpineTest.cpp에서 발생.

그래서 SpineTest.h, SpineTest.cpp 사용하는 부분 싹 다 주석처리.

갹!!!성공!!!!

다양한 예제가 있었다.

그리고 이제 또 분석하면 된다...

버그해결>분석>버그해결>분석>버그해결>분석

ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ

반응형
▲ top