Skip to main content

Posts

Showing posts from 2015

dealing with textureAtlas and spritekit all about preloading texture atlas and remove them when you not need them anymore

spritekit is a cool 2d framework designed by apple with support fast 2d graphics rendering one of the killer feature of sprite kit is texture atlas a what is a texture atlas https://developer.apple.com/library/ios/recipes/xcode_help-texture_atlas/_index.html working with texture atlas in sprite kit is very easy. example #import "GameScene.h" @implementation GameScene {     UIImage *defaultImg;     int MCrow;     int MCcoloum;     float imgWidth;     float imgHeight;     NSArray *atlasArray;     NSMutableArray *fetchedAtlas;     NSDictionary *dict1;     NSDictionary *dict2;     NSDictionary *dict3;     NSDictionary *dict4;     NSDictionary *dict5;     NSDictionary *dict6;     NSDictionary *dict7;     SKSpriteNode *node; } -( void )didMoveToView:( SKView *)view { ...

working with blocks and function which takes block as a parameter in objective c

how to create a block in objective c define a block in .h file  /*here i created a block  addPhysicsBody is the name of block ^ without is block can’t be completed  so block is defined ^addPhysicsBody typedef void (^addPhysicsBody)( CGPoint ); where void is return type and CGpoint is parameter where bolded part is a parameter taken by block 2)  step 2 @property (copy) addPhysicsBody clickBlock; add block as a property and please remember that this property is copy   because a block needs to be copied to keep track of its captured state outside of the original scope by apple  define a function in .h file that takes block as a parameter this is necessary while creating block with function  - (void)getPhysicsBody:( void (^)(CGPoint) )finishBlock; where above bolded part is block with its para...

moving from one UIViewController to another from sprite kit SKScene

create a new  NSNotificationCenter inside your  UIViewController class inside  viewDidAppear function  1). -( void )viewDidAppear:( BOOL )animated {     [[ NSNotificationCenter defaultCenter ] addObserver : self selector : @selector (disMissViewController) name : @"disMissViewController"   object : nil ]; } 2.) create selector  -( void )disMissViewController{         //in case of story board     UIStoryboard *storyboard = [ UIStoryboard storyboardWithName : @"Main"   bundle : nil ];     mainView = [storyboard instantiateViewControllerWithIdentifier : @"main" ];     //in case of code       mainView =[[ UIViewController alloc ] init ];     [ self presentViewController : newview Controller   animated : YES completion :^{              }];     //remove...

handling multiple sprite animation in cocos2dx3.2

many times in gaming world we need to handle multiple animation for e.g. when hero is running we have to call running sprite or frames when hero is jumping we need to call jumping frame here is my solution for that ==================== .h file // //  spriteSheet.h //  firegame // //  Created by Manish on 22/03/15. // // #ifndef __firegame__spriteSheet__ #define __firegame__spriteSheet__ #include "cocos2d.h" class spriteSheet : public cocos2d :: SpriteBatchNode {     public :         //constructor         spriteSheet();         //destructor         ~spriteSheet();         static spriteSheet * create( /*spritesheet reference*/ std :: string __spriteReference, /*plist reference */ std :: string __plistname, /*first frame of spritesheet*/ std :: string firstframe);             void init...