.net barcode generator code project 10: Working with Tilemaps in Objective-C

Encoding ECC200 in Objective-C 10: Working with Tilemaps

CHAPTER 10: Working with Tilemaps
Generate Data Matrix 2d Barcode In Objective-C
Using Barcode drawer for iPhone Control to generate, create Data Matrix ECC200 image in iPhone applications.
www.OnBarcode.com
Barcode Encoder In Objective-C
Using Barcode creation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Figure 10 12. The tilemap with object layer rectangles displayed using OpenGL ES code
GTIN - 128 Generation In Objective-C
Using Barcode generator for iPhone Control to generate, create GS1-128 image in iPhone applications.
www.OnBarcode.com
Generating UPC Code In Objective-C
Using Barcode encoder for iPhone Control to generate, create GTIN - 12 image in iPhone applications.
www.OnBarcode.com
The (void) draw method just needs to be in the class, and it will be called automatically every frame. However, you should refrain from using the draw method to modify properties of nodes, as this can interfere with drawing the nodes. Listing 10 5 shows the draw method of the TileMapLayer class.
Printing ANSI/AIM Code 128 In Objective-C
Using Barcode creator for iPhone Control to generate, create Code-128 image in iPhone applications.
www.OnBarcode.com
Barcode Creator In Objective-C
Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Listing 10 5. Drawing ObjectLayer Rectangles -(void) draw { CCNode* node = [self getChildByTag:TileMapNode]; NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap"); CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node; // Get the object layer CCTMXObjectGroup* objectLayer = [tileMap objectGroupNamed:@"ObjectLayer"]; // Make the line 3 pixels thick glLineWidth(3.0f); glColor4f(1, 0, 1, 1); int numObjects = [[objectLayer objects] count]; for (int i = 0; i < numObjects; i++) { NSDictionary* properties = [[objectLayer objects] objectAtIndex:i]; CGRect rect = [self getRectFromObjectProperties:properties tileMap:tileMap]; [self drawRect:rect]; } glLineWidth(1.0f); glColor4f(1, 1, 1, 1); }
Generate ANSI/AIM Code 39 In Objective-C
Using Barcode creator for iPhone Control to generate, create Code 3 of 9 image in iPhone applications.
www.OnBarcode.com
GTIN - 8 Creator In Objective-C
Using Barcode creator for iPhone Control to generate, create EAN-8 Supplement 2 Add-On image in iPhone applications.
www.OnBarcode.com
First, I get the tilemap by its tag and then the CCTMXObjectGroup by using the objectGroupNamed method. I then set the line width to 3 pixels by using the OpenGL ES method glLineWidth, and set the color to purple by using glColor4f. This affects line thickness and color of all subsequent lines drawn with OpenGL ES not just in the current method, but possibly other nodes that use OpenGL ES code for drawing (e.g., any of the convenience methods for drawing lines, circles, and polygons defined in
Data Matrix 2d Barcode Encoder In Objective-C
Using Barcode creation for iPhone Control to generate, create DataMatrix image in iPhone applications.
www.OnBarcode.com
Data Matrix Decoder In Visual C#
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 11: Working with Tilemaps
Decoding ECC200 In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Data Matrix ECC200 Generation In None
Using Barcode generation for Font Control to generate, create ECC200 image in Font applications.
www.OnBarcode.com
cocos2d s CCDrawingPrimitives.h header file). That is why I reset glLineWidth and glColor4f after I m done drawing. It is good style in OpenGL code to leave its state like you found it; otherwise, it might alter the way other draw code produces its output. OpenGL is a state machine, so every setting you change is remembered and may affect subsequent drawing methods. To avoid this, any OpenGL settings you change should be set back to a safe default after you re done drawing. NOTE: Code inside the -(void) draw method is always drawn at a z-order of 0. It is also drawn before all other nodes at z-order 0, which means that any OpenGL ES code will be overdrawn by other nodes if they are also at z-order 0. In the case of the object layer draw code, I had to add the tileMap at a z-order of 1 for the rectangles to be drawn over the tilemap. Just like before, I iterate over all object layer objects, and get their properties from NSDictionary to get the CGRect of that object, which is then passed to the drawRect method. Unfortunately, cocos2d omitted this particular convenience method, but it s easy enough to add using ccDrawLine, as Listing 10 6 shows.
Scanning PDF 417 In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
GTIN - 128 Decoder In VB.NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Listing 10 6. Drawing a Rectangle -(void) drawRect:(CGRect)rect { // The rect is drawn using four lines CGPoint pos1, pos2, pos3, pos4; pos1 = CGPointMake(rect.origin.x, rect.origin.y); pos2 = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height); pos3 = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height); pos4 = CGPointMake(rect.origin.x + rect.size.width, rect.origin.y); ccDrawLine(pos1, ccDrawLine(pos2, ccDrawLine(pos3, ccDrawLine(pos4, } pos2); pos3); pos4); pos1);
Code128 Generation In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create Code128 image in .NET framework applications.
www.OnBarcode.com
PDF 417 Printer In Visual Studio .NET
Using Barcode creator for .NET framework Control to generate, create PDF417 image in VS .NET applications.
www.OnBarcode.com
For each corner of the rectangle, a CGPoint is created, which is then used in four ccDrawLine methods to draw the lines between the corners of the rectangle. You may want to remember this method and put it in a safe place, because you ll probably need it again. Note that the draw and drawRect methods are enclosed in #ifdef DEBUG and #endif statements. This means that the object layer rectangles will not be drawn in release builds, because I only need them for debugging and illustration purposes the end user should never see them.
Encoding Data Matrix 2d Barcode In VS .NET
Using Barcode maker for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
www.OnBarcode.com
Code 3 Of 9 Maker In None
Using Barcode drawer for Word Control to generate, create Code 39 Extended image in Word applications.
www.OnBarcode.com
#ifdef DEBUG -(void) drawRect:(CGRect)rect { ... } -(void) draw
Printing Barcode In None
Using Barcode creation for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Code 39 Full ASCII Creator In Visual Basic .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create ANSI/AIM Code 39 image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 10: Working with Tilemaps
{ ... } #endif
Scrolling the Tilemap
The best part comes last: scrolling. It s actually straightforward because only the CCTMXTiledMap needs to be moved. In the Tilemap04 project, I ve added the call to the centerTileMapOnTileCoord method in ccTouchesBegan right after obtaining the tile coordinates of the touch:
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ... // Get the position in tile coordinates from the touch location CGPoint touchLocation = [self locationFromTouches:touches]; CGPoint tilePos = [self tilePosFromLocation:touchLocation tileMap:tileMap]; // Move tilemap so that the touched tile is at the center of the screen [self centerTileMapOnTileCoord:tilePos tileMap:tileMap]; ... }
Listing 10 7 shows the centerTileMapOnTileCoord method, which moves the tilemap so that the touched tile is at the center of the screen. It also stops the tilemap from scrolling further if any tilemap border already aligns with the screen edge.
Listing 10 7. Centering the Tilemap on a Tile Coordinate -(void) centerTileMapOnTileCoord:(CGPoint)tilePos tileMap:(CCTMXTiledMap*)tileMap { // Center tilemap on the given tile pos CGSize screenSize = [[CCDirector sharedDirector] winSize]; CGPoint screenCenter = CGPointMake(screenSize.width * 0.5f, screenSize.height * 0.5f); // Tile coordinates are counted from upper-left corner tilePos.y = (tileMap.mapSize.height - 1) - tilePos.y; // Point is now at lower-left corner of the screen CGPoint scrollPosition = CGPointMake(-(tilePos.x * tileMap.tileSize.width), -(tilePos.y * tileMap.tileSize.height)); // Offset point to center of screen and center of tile scrollPosition.x += screenCenter.x - tileMap.tileSize.width * 0.5f; scrollPosition.y += screenCenter.y - tileMap.tileSize.height * 0.5f; // Make sure tilemap scrolling stops at the tilemap borders scrollPosition.x = MIN(scrollPosition.x, 0); scrollPosition.x = MAX(scrollPosition.x, -screenSize.width); scrollPosition.y = MIN(scrollPosition.y, 0); scrollPosition.y = MAX(scrollPosition.y, -screenSize.height);
Copyright © OnBarcode.com . All rights reserved.