10

I used below code in Cocos2d 1.0 and Cocos2d 2.0, but it seems not found in Cocos2d 3.0

CGSize s = [[CCDirector sharedDirector] winSize];

How to get screen size in Cocos2d 3.0 ?

James Webster
  • 31,873
  • 11
  • 70
  • 114
iPhoneProcessor
  • 4,980
  • 6
  • 27
  • 49

1 Answers1

31

You can use viewSize.

    CGSize s = [CCDirector sharedDirector].viewSize;
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Guru
  • 21,652
  • 10
  • 63
  • 102
  • This returns `{512.00, 384.00}` on an iPad Air device and simulator. Any idea why? (Cocos2D version 3.4.3-develop). – trojanfoe Apr 10 '15 at 18:40
  • @trojanfoe, I just logged size from cocos2d 3.4.3 and got (768.0,1024.0). I took Cocos2d from Sprite builder and working good. – Guru Apr 10 '15 at 19:52
  • 1
    Well it's weird as using `viewSizeInPixels` (is it?) returns the expected 2048 x 1536, which I am now using to calculate the global scale value. – trojanfoe Apr 11 '15 at 09:24
  • I believe this is because viewSize returns the OpenGL size, while size in pixels is the actual device screen size. (just a theory though) – Pochi Feb 17 '16 at 08:47
  • 1
    Director::getInstance()->getOpenGLView()->getFrameSize() does return the actual device size though, but this is for cocos2dx – Pochi Feb 17 '16 at 08:53