Skip to main content

Posts

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...

creating a endless parallax scrolling background in spritekit and objective c

// //  cloneParallax.h #import <SpriteKit/SpriteKit.h> @interface cloneParallax : SKSpriteNode {      } -( id ) initParallax:( float )PtotalWidth parallaxSpeed:( float )Pspeed parallaxY:( float )Py; //properties @property float PtotalWidth; @property SKTexture *Ptexture; @property float RXY; @property float Pspeed; @property float Py; @property float clonewidth; -( void )DrawParallax:( SKTexture *)Ptexture  scaleXY:( float )R; -( void )DrawParallaxSprites:( NSMutableArray *)textureArray widthofSprite:( float )_width scaleXY:( float )R; -( void ) updateParallax:( CFTimeInterval )interval; @end // // //  cloneParallax.m //  milkhunt // //  Created by Manish Chauhan on 26/12/13. //  Copyright (c) 2013 skidos. All rights reserved. // #import "cloneParallax.h" #import "sprite.h" @implementation cloneParallax {      int numberofcl...

Algorithm for generating weighed random numbers in objective c

-( int ) randomIndexByWeights:( NSArray * )weights {     // add weights     int weightsTotal = 0 ;          for ( int i = 0 ; i < [weights count ]; i++ )     {         weightsTotal+= [[weights objectAtIndex : i] intValue ];              }     float randomNum = (( float ) rand () / RAND_MAX ) * 1 ;     int rand =( int )(randomNum * weightsTotal);     // step through array to find where that would be     weightsTotal = 0 ;     for ( int x = 0 ; x < [weights count ]; x++ )     {                  weightsTotal+= [[weights objectAtIndex : x] intValue ];                  if ( weightsTotal >= rand)         {             return x; ...

Creating a SpriteBatchNode subclass for sprite animation

SpriteBatchNode is one of the most usefull class of cocos2d-x-3.2 Now here I am creating a subclass which is extend from SpriteBatchNode You .h file #ifndef _ANIMALANIMATION_H_ #define _ANIMALANIMATION_H_ #include "cocos2d.h" class animalAnimation : public cocos2d:: SpriteBatchNode {     public :                       animalAnimation();         ~animalAnimation();         static animalAnimation * create(std:: string spriteReference,std:: string plistname,std:: string firstframe, int frames);         void initOptions(std:: string plistname,std:: string firstframe, int frames);               }; #endif // Now .cpp file #include "animalAnim...
Installing  cocos2dx 3.2 for android and window7 (part2) For android  You need following tool ·          JDK/SDK 1.6+ need to be installed in your system http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html download path is above install it you don’t have java installed in your system ·          NDK r9d+ https://developer.android.com/tools/sdk/ndk/index.html choose version 9  not 10 ·          Apache Ant http://ant.apache.org/bindownload.cgi install apace ant ·          Python 2.7.5 aleady installed if not then install it ·          Download Eclipse with ADT Bundle http://developer.android.com/sdk/index.html form the above link now ·          now...