Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clean up the code as per the 'Cleaning Up' chapter

  • Loading branch information...
commit da955a5ef0d4c6627b120acdb85699c597aa3e7b 1 parent 7377729
clawoo authored September 08, 2011
70  Classes/HelloWorldScene.cpp
@@ -20,7 +20,6 @@ enum
20 20
 HelloWorld::HelloWorld()
21 21
 {
22 22
 	setIsTouchEnabled( true );
23  
-	setIsAccelerometerEnabled( true );
24 23
     
25 24
 	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
26 25
 	//UXLOG(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height);
@@ -78,19 +77,6 @@ HelloWorld::HelloWorld()
78 77
 	groundBox.SetAsEdge(b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,0));
79 78
 	groundBody->CreateFixture(&groundBox, 0);
80 79
     
81  
-	
82  
-	//Set up sprite
83  
-	
84  
-	CCSpriteBatchNode *mgr = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 150);
85  
-	addChild(mgr, 0, kTagSpriteManager);
86  
-	
87  
-	addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) );
88  
-	
89  
-	CCLabelTTF *label = CCLabelTTF::labelWithString("Tap screen", "Marker Felt", 32);
90  
-	addChild(label, 0);
91  
-	label->setColor( ccc3(0,0,255) );
92  
-	label->setPosition( CCPointMake( screenSize.width/2, screenSize.height-50) );
93  
-	
94 80
 	schedule( schedule_selector(HelloWorld::tick) );
95 81
 }
96 82
 
@@ -119,41 +105,6 @@ void HelloWorld::draw()
119 105
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	
120 106
 }
121 107
 
122  
-void HelloWorld::addNewSpriteWithCoords(CCPoint p)
123  
-{
124  
-	//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
125  
-	CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);
126  
-	
127  
-	//We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
128  
-	//just randomly picking one of the images
129  
-	int idx = (CCRANDOM_0_1() > .5 ? 0:1);
130  
-	int idy = (CCRANDOM_0_1() > .5 ? 0:1);
131  
-	CCSprite *sprite = CCSprite::spriteWithBatchNode(sheet, CCRectMake(32 * idx,32 * idy,32,32));
132  
-	sheet->addChild(sprite);
133  
-	
134  
-	sprite->setPosition( CCPointMake( p.x, p.y) );
135  
-	
136  
-	// Define the dynamic body.
137  
-	//Set up a 1m squared box in the physics world
138  
-	b2BodyDef bodyDef;
139  
-	bodyDef.type = b2_dynamicBody;
140  
-	bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
141  
-	bodyDef.userData = sprite;
142  
-	b2Body *body = world->CreateBody(&bodyDef);
143  
-	
144  
-	// Define another box shape for our dynamic body.
145  
-	b2PolygonShape dynamicBox;
146  
-	dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
147  
-	
148  
-	// Define the dynamic body fixture.
149  
-	b2FixtureDef fixtureDef;
150  
-	fixtureDef.shape = &dynamicBox;	
151  
-	fixtureDef.density = 1.0f;
152  
-	fixtureDef.friction = 0.3f;
153  
-	body->CreateFixture(&fixtureDef);
154  
-}
155  
-
156  
-
157 108
 void HelloWorld::tick(ccTime dt)
158 109
 {
159 110
 	//It is recommended that a fixed time step is used with Box2D for stability
@@ -180,27 +131,6 @@ void HelloWorld::tick(ccTime dt)
180 131
 	}
181 132
 }
182 133
 
183  
-void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
184  
-{
185  
-	//Add a new body/atlas sprite at the touched location
186  
-	CCSetIterator it;
187  
-	CCTouch* touch;
188  
-    
189  
-	for( it = touches->begin(); it != touches->end(); it++) 
190  
-	{
191  
-		touch = (CCTouch*)(*it);
192  
-        
193  
-		if(!touch)
194  
-			break;
195  
-        
196  
-		CCPoint location = touch->locationInView(touch->view());
197  
-		
198  
-		location = CCDirector::sharedDirector()->convertToGL(location);
199  
-        
200  
-		addNewSpriteWithCoords( location );
201  
-	}
202  
-}
203  
-
204 134
 CCScene* HelloWorld::scene()
205 135
 {
206 136
     // 'scene' is an autorelease object
2  Classes/HelloWorldScene.h
@@ -21,9 +21,7 @@ class HelloWorld : public cocos2d::CCLayer {
21 21
     static cocos2d::CCScene* scene();
22 22
     
23 23
     // adds a new sprite at a given coordinate
24  
-    void addNewSpriteWithCoords(cocos2d::CCPoint p);
25 24
     virtual void draw();
26  
-    virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
27 25
     void tick(cocos2d::ccTime dt);
28 26
     
29 27
 private:
4  CuteAPultCocos2D-x.xcodeproj/project.pbxproj
@@ -17,7 +17,6 @@
17 17
 		506EDB88102F4C4000A389B3 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EDB87102F4C4000A389B3 /* libz.dylib */; };
18 18
 		506EDBA5102F4C9F00A389B3 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EDBA4102F4C9F00A389B3 /* AVFoundation.framework */; };
19 19
 		506EE1A91030508200A389B3 /* libcocos2d libraries.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 506EE05E10304ED200A389B3 /* libcocos2d libraries.a */; };
20  
-		50F4144810692EE7002A0D5E /* blocks.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144310692EE7002A0D5E /* blocks.png */; };
21 20
 		50F4144910692EE7002A0D5E /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144410692EE7002A0D5E /* Default.png */; };
22 21
 		50F4144B10692EE7002A0D5E /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 50F4144610692EE7002A0D5E /* Icon.png */; };
23 22
 		BF126CF31373EEFC00C4ABC5 /* CCUserDefault.h in Headers */ = {isa = PBXBuildFile; fileRef = BF126CF21373EEFC00C4ABC5 /* CCUserDefault.h */; };
@@ -375,7 +374,6 @@
375 374
 		506EDB87102F4C4000A389B3 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
376 375
 		506EDBA4102F4C9F00A389B3 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
377 376
 		506EE05E10304ED200A389B3 /* libcocos2d libraries.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libcocos2d libraries.a"; sourceTree = BUILT_PRODUCTS_DIR; };
378  
-		50F4144310692EE7002A0D5E /* blocks.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blocks.png; sourceTree = "<group>"; };
379 377
 		50F4144410692EE7002A0D5E /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
380 378
 		50F4144610692EE7002A0D5E /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon.png; sourceTree = "<group>"; };
381 379
 		BF126CF21373EEFC00C4ABC5 /* CCUserDefault.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCUserDefault.h; sourceTree = "<group>"; };
@@ -842,7 +840,6 @@
842 840
 				E02BB540126CA5DA006E46A2 /* Icon-Small.png */,
843 841
 				E02BB541126CA5DA006E46A2 /* Icon-Small-50.png */,
844 842
 				E02BB542126CA5DA006E46A2 /* Icon-72.png */,
845  
-				50F4144310692EE7002A0D5E /* blocks.png */,
846 843
 				50F4144410692EE7002A0D5E /* Default.png */,
847 844
 				50F4144610692EE7002A0D5E /* Icon.png */,
848 845
 			);
@@ -1700,7 +1697,6 @@
1700 1697
 			isa = PBXResourcesBuildPhase;
1701 1698
 			buildActionMask = 2147483647;
1702 1699
 			files = (
1703  
-				50F4144810692EE7002A0D5E /* blocks.png in Resources */,
1704 1700
 				50F4144910692EE7002A0D5E /* Default.png in Resources */,
1705 1701
 				50F4144B10692EE7002A0D5E /* Icon.png in Resources */,
1706 1702
 				E02BB544126CA5DA006E46A2 /* Icon@2x.png in Resources */,
BIN  Resources/blocks.png

0 notes on commit da955a5

Please sign in to comment.
Something went wrong with that request. Please try again.