'2014/01'에 해당되는 글 185건

  1. 2014.01.16 열혈강의 cocos2d-x
  2. 2014.01.15 c언어 공부할때 참고 사이트
  3. 2014.01.15 관련 자료
  4. 2014.01.15 안드로이드 NDK 책
  5. 2014.01.14 [Box2D] Box2D 기본 예제 디버그 모드 및 스프라이트 생성
  6. 2014.01.14 cocos2d-x 멀티 터치 처리하기
  7. 2014.01.14 Box2d 사용시(처음에 시작시 체크하지 않았을시)
  8. 2014.01.14 “Game Programming Gems 1권 – 3.3 A* 길찾기 알고리즘의 기초”
  9. 2014.01.14 [런게임] 유니티 3D로 러너 게임 만들기 - 완성본
  10. 2014.01.14 [런게임] 유니티 3D로 러너 게임 만들기 - 파티클 이펙트

열혈강의 cocos2d-x

|

1월 24 일날 출시

사면도움이 될듯

'보고싶은책' 카테고리의 다른 글

사고 싶은 책  (0) 2014.08.21
c# 기본서 추천(c# IN DEPTH)  (0) 2014.01.19
열혈강의 cocos2d-x  (0) 2014.01.16
안드로이드 NDK 책  (0) 2014.01.15
“Game Programming Gems 1권 – 3.3 A* 길찾기 알고리즘의 기초”  (0) 2014.01.14
프로그래머를 위한 책  (0) 2014.01.13
Trackback 0 And Comment 0

c언어 공부할때 참고 사이트

|

http://www.soen.kr

Trackback 0 And Comment 0

관련 자료

|

http://www.raywenderlich.com

'잡다한것들전부 > 2D 관련 자료' 카테고리의 다른 글

유니티 2디 간단 사용영상  (0) 2014.01.22
관련 자료  (0) 2014.01.15
Trackback 0 And Comment 0

안드로이드 NDK 책

|

안드로이드 NDK 네이티브 프로그래밍(위키북스 임베디드 & 모바일 시리즈)
유일한 국내 번역 안드로이드 NDK 책?

'보고싶은책' 카테고리의 다른 글

c# 기본서 추천(c# IN DEPTH)  (0) 2014.01.19
열혈강의 cocos2d-x  (0) 2014.01.16
안드로이드 NDK 책  (0) 2014.01.15
“Game Programming Gems 1권 – 3.3 A* 길찾기 알고리즘의 기초”  (0) 2014.01.14
프로그래머를 위한 책  (0) 2014.01.13
Code Complete  (0) 2014.01.13
Trackback 0 And Comment 0

[Box2D] Box2D 기본 예제 디버그 모드 및 스프라이트 생성

|

RecipeCollection01.zip


전체소스




#ifndef __CH4_BASICSETUP__

#define __CH4_BASICSETUP__



#include "cocos2d.h"

#include "Recipe.h"

#include "Box2D/Box2D.h"

#include <GLES-Render.h>


//32 픽셀 = 1미터

#define PTM_RATIO 32



class Ch4_BasicSetup : public Recipe

{

private:

b2World* world;

GLESDebugDraw *m_debugDraw;

public:

virtual CCLayer* runRecipe();

void addLevelBoundaries();

void step(float dt);

virtual void draw();

void addNewSpriteWithCoords(CCPoint p);

void ccTouchesEnded(CCSet * touches, CCEvent * event);

};


CCLayer* Ch4_BasicSetup::runRecipe()

{

Recipe::runRecipe();

this->setTouchEnabled(true);

    /* Box2D 초기화 */

    

// 중력의 방향을 결정한다.

b2Vec2 gravity = b2Vec2(0.0f, -30.0f);

    

// 월드를 생성한다.

world = new b2World(gravity);

world->SetAllowSleeping(true);

world->SetContinuousPhysics(true);

    

//디버그 드로잉 초기화

m_debugDraw = new GLESDebugDraw( PTM_RATIO );

world->SetDebugDraw(m_debugDraw);

uint32 flags = 0;

flags += b2Draw::e_shapeBit;

m_debugDraw->SetFlags(flags);

//레벨 경계 생성

this->addLevelBoundaries();

    

//블록생성을 위한 배치 노드 생성

CCSpriteBatchNode *batch = CCSpriteBatchNode::create("blocks.png", 150);

this->addChild(batch, 0, 0);

    

//새로운 블록 추가

CCSize screenSize = CCDirector::sharedDirector()->getWinSize();

this->addNewSpriteWithCoords(ccp(screenSize.width/2, screenSize.height/2));

    

//스텝 메서드 스케줄링

this->schedule(schedule_selector(Ch4_BasicSetup::step));

return this;

}


//양쪽 사각형 영역 설정

void Ch4_BasicSetup::addLevelBoundaries()

{

CCSize winSize = CCDirector::sharedDirector()->getWinSize();

    

// 가장자리(테두리) 지정해 공간(Ground Box) 만든다.

    

// 바디데프에 좌표를 설정한다.

b2BodyDef groundBodyDef;

groundBodyDef.position.Set(0,0);

    

// 월드에 바디데프의 정보(좌표) 바디를 만든다.

b2Body *groundBody = world->CreateBody(&groundBodyDef);

    

    

// 가장자리(테두리) 경계선을 그릴 있는 모양의 객체를 만든다.

b2EdgeShape groundEdge;

b2FixtureDef boxShapeDef;

boxShapeDef.shape = &groundEdge;

    

    

// 에지 모양의 객체에 Set(1 , 2)으로 선을 만든다.

// 그리고 바디(groundBody) 쉐이프(groundEdge) 고정시킨다.

    

// 아래쪽

groundEdge.Set(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0));

groundBody->CreateFixture(&boxShapeDef);

    

// 왼쪽

groundEdge.Set(b2Vec2(0,0), b2Vec2(0, winSize.height/PTM_RATIO));

groundBody->CreateFixture(&boxShapeDef);

    

// 위쪽

groundEdge.Set(b2Vec2(0, winSize.height/PTM_RATIO),

                   b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO));

groundBody->CreateFixture(&boxShapeDef);

    

// 오른쪽

groundEdge.Set(b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO),

                   b2Vec2(winSize.width/PTM_RATIO, 0));

groundBody->CreateFixture(&boxShapeDef);

}

//물리적 위치를 이용해서 그래픽 위치를 갱신

void Ch4_BasicSetup::step( float dt )

{

int32 velocityIterations = 8;

int32 positionIterations = 3;

    

world->Step(dt, velocityIterations, positionIterations);

    

for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())

{

if (b->GetUserData() != NULL) {

CCSprite *obj = (CCSprite*)b->GetUserData();

obj->setPosition( CCPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) );

obj->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) );

}

}

}

/* 디버그 그리기 데이터 */

void Ch4_BasicSetup::draw()

{

    //텍스쳐 비활성화

glDisable(GL_TEXTURE_2D);

glDisableClientState(GL_COLOR_ARRAY);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

    

world->DrawDebugData();

    

    //텍스쳐 재활성화

glEnable(GL_TEXTURE_2D);

glEnableClientState(GL_COLOR_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

}

/* 텍스처 입힌 블록을 추가합니다. */

void Ch4_BasicSetup::addNewSpriteWithCoords( CCPoint p )

{

CCSpriteBatchNode *batch = (CCSpriteBatchNode*) this->getChildByTag(0);

    

    //랜덤하게 텍스쳐 처리된 블록을 생성

int idx = (CCRANDOM_0_1() > .5 ? 0:1);

int idy = (CCRANDOM_0_1() > .5 ? 0:1);

CCSprite *sprite = CCSprite::createWithTexture(batch->getTexture(), CCRectMake(32 * idx,32 * idy,32,32));

batch->addChild(sprite);

    

sprite->setPosition(ccp( p.x, p.y));

    

    //물체 정의 생성

b2BodyDef bodyDef;

bodyDef.type = b2_dynamicBody;

    

bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);

bodyDef.userData = sprite;

b2Body *body = world->CreateBody(&bodyDef);

    

//동적 본체를 위한 또다른 상자 모양 정의

b2PolygonShape dynamicBox;

dynamicBox.SetAsBox(.5f, .5f);//1m 상자의 중간 지점

    

//동적 물체 픽스쳐 정의.

b2FixtureDef fixtureDef;

fixtureDef.shape = &dynamicBox;

fixtureDef.density = 1.0f;

fixtureDef.friction = 0.3f;

body->CreateFixture(&fixtureDef);

}

//클릭시 물체 추가 생성

void Ch4_BasicSetup::ccTouchesEnded( CCSet * touches, CCEvent * event )

{

//멀티터치 처리

CCSetIterator it = touches->begin();

    

CCTouch* touch;

for( int iTouchCount = 0; iTouchCount < touches->count(); iTouchCount++ )

{

touch = (CCTouch*)(*it);

CCPoint location = touch->getLocationInView();

location = CCDirector::sharedDirector()->convertToGL(location);

this->addNewSpriteWithCoords(location);

it++;

}

}

#endif




Trackback 0 And Comment 0

cocos2d-x 멀티 터치 처리하기

|


void HelloWorld::ccTouchesEnded( CCSet * touches, CCEvent * event )

{

//멀티터치 처리

CCSetIterator it = touches->begin();

CCTouch* touch;

for( int iTouchCount = 0; iTouchCount < touches->count(); iTouchCount++ )

{

touch = (CCTouch*)(*it);

CCPoint location = touch->getLocationInView();

location = CCDirector::sharedDirector()->convertToGL(location);

it++;

}

}

Trackback 0 And Comment 0

Box2d 사용시(처음에 시작시 체크하지 않았을시)

|

처음 프로젝트를 생성할때 Box2d 를 선택하지 않고 프로젝트를 만들면 

각종 오류들이뜸


속성-링커-입력-추가종속성- libBox2d.lib추가

속성-c/c++-추가포함디렉터리 - $(SolutionDir)external 추가


하면 대강 오류는 없어짐

Trackback 0 And Comment 0

“Game Programming Gems 1권 – 3.3 A* 길찾기 알고리즘의 기초”

|

“Game Programming Gems 1권 – 3.3 A* 길찾기 알고리즘의 기초”

Trackback 0 And Comment 0

[런게임] 유니티 3D로 러너 게임 만들기 - 완성본

|

Trackback 0 And Comment 0

[런게임] 유니티 3D로 러너 게임 만들기 - 파티클 이펙트

|

파티클 이펙트

지금 까지 우리는 게임의 기능적인 면을 만들었다. 하지만 Scene 공간에 텅 빈 느낌을 채워주고 싶다. 이것을 파티클 이펙트로 채울 생각이다.


 particle system을 생성하자. (GameObject / Create Other / Particle System) 이름은 Dust Emitter로 짓자. Runner의 자식으로 두고 위치는 (25, 0, 0)로 설정하고 rotation은 reset해준다, 이렇게 하면 항상 카메라를 따라다닌다.

Set Start Lifetime 를 Random Between Two Constants 으로 설정하고 값을 6과 10으로 설정해준다. 그리고 Start Speed 는 0으로 설정해준다. 이것을 사용하면 입자의 크기가 일정하게 시작된다. 또한 Simulation Space는 World로 변경해준다. 이것은 Runner에 의해서 파티클이 움직이지 않게 해준다. Start Size는 Random Between Two Constants으로 설정해주고 값은 0.2 와 0.8로 맞춰준다.

shape 는 box로 설정하고 with 수치는 (1, 30, 10)로 설정해주고 Emission 는 20으로 설정한다.

Velocity Over Lifetime은, world space로 설정하고 random range between two constants로 설정해준다 값은  (-1, -1, 0) 그리고 (-4, 1, 0)로 설정한다. 이것은 파티클 각각의 움직임을 나타내어준다.

마지막으로 Color over Lifetime 의 그라디언트를 처음에는 0 그리고 나중에는 100%로 맞춰주자. 이것은 페이드인 효과가 나타난다.

그다음 particle system을 복제하고, Runner의 자식으로 둔다, position을 reset 하고 이름은 Trail Emitter로 짓는다. 이것은 러너의 흔적을 나타낼 파티클입니다.

Shape를 Mesh로 변경하고 and cube로 설정해준다. 그리고 Velocity over Lifetime을 해제한다.

Start Lifetime을   1 과 2 로 Start Size 는 0.2 와 0.4로 설정한다.

dust trail scene
Particle systems.

우리는 게임중일때 파티클을 생성할때는 매니저 클래스를 만들어서 생성할수 있습니다. ParticleSystemManager라는 C# script를 만들고  Managers 폴더에 넣습니다. 또한 이 스크립트를 넣을 빈 오브젝트도 생서해줍시다.

 ParticleSystemManager 에서는 오직 파티클의 보이고 안보이고 만 해줍니다. 우리는  particleSystems 배열을 사용해서 관리합니다. 

using UnityEngine;

public class ParticleSystemManager : MonoBehaviour {

	public ParticleSystem[] particleSystems;

	void Start () {
		GameEventManager.GameStart += GameStart;
		GameEventManager.GameOver += GameOver;
		GameOver();
	}

	private void GameStart () {
		for(int i = 0; i < particleSystems.Length; i++){
			particleSystems[i].Clear();
			particleSystems[i].enableEmission = true;
		}
	}

	private void GameOver () {
		for(int i = 0; i < particleSystems.Length; i++){
			particleSystems[i].enableEmission = false;
		}
	}
}
managergame
Particles in action.
모든 게임을 완성했습니다! 점프가 가능하며, 흔적도 남고 파워업아이템도 만들었고! 점수또한 보입니다.! 그리고 배경또한 스크롤 됩니다. 이것은 좋은 프로토타입이고 당신은 이것을 통해서 멋진 게임을 만들수도 있습니다! 수고하셨습니다.







패키지 파일


runner.unitypackage



Trackback 0 And Comment 0
prev | 1 | ··· | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ··· | 19 | next