Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to obtain a CCSprite's width and height in cocos2d for iphone

That's the question xD

Given an instance of a CCSprite in cocos2d in iphone, what method can I use to obtain the image width and height?

like image 885
Manuel Araoz Avatar asked Mar 23 '10 21:03

Manuel Araoz


1 Answers

The CCSprite class has a bounding box property that's a CGRect:

  CCSprite *sprite = [CCSprite spriteWithFile: @"file.png"];   int width = [sprite boundingBox].size.width; 

I added a width and height methods to my CCSprite subclass.

-(CGFloat) width {     return [self boundingBox].size.width; }  -(CGFloat) height {     return [self boundingBox].size.height; } 
like image 200
robterrell Avatar answered Sep 22 '22 17:09

robterrell