Skip to main content

Posts

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...
Installing  cocos2dx 3.2 for android and window7 (part1) === ========================================== statement above reference image below First would let I would to run cocos2dx on windows 7 1           1)       Download cocos2dx  from http://cocos2d-x.org/download be sure you would download              Latest version 3.2              download python 2.7 note please down 2.7 not 3              Install python 2.7 you can download it from              https://www.python.org/downloads/     2           2)       Now unzip the folder 3           3)       Save it in a suitable location in your hard drive like below 4) next step to download Mic...

adding multiple sprite animation or texture animation in a sprite using sprite kit

while working with textures animations many time you need to store multiple animation with a single sprite for eg hero is a sprite  now hero contain different animation such as walk left , walk right ,walk  up, walk down so here i come with a solution  in .m file copy this code =================================== #import <SpriteKit/SpriteKit.h> //spriteSequence @interface spriteSheet : SKSpriteNode {     //private variable no one    } @property SKTexture   *startingFrame; @property SKSpriteNode *animatedsprite; @property SKAction   *Animation; @property SKAction   *currentAction; @property NSMutableArray *spritesArray; @property NSMutableArray *frameRateArray; @property NSMutableArray *actionKeys; //public mehods -( id ) initSpritesheet:( NSString *)firstFrame; -( void )addAnimation:( NSMutableArray *)frames frameRate:( float )time withKey:( NS...