1

Is it possible to use a large image in Cocos2D, and allow, via swiping or pinching, for the user to zoom in and out?

I see from this post, that the max res for a Cocos2D image is 2048x2048. That is obviously larger than a device viewport, so I want the user to be able to move around the image.

I'm not creating a game, I'm making a sort of interactive biological cell, that will allow the user to tap arbitrary organelles, and see a popup of information about them.

Here is an idea of what the image will be, and obviously cramming the whole thing into a device viewport is not possible:

Cell

So really, before I delve too deep into this project, I'm just curious as to whether it is possible to use a large image, that allows the user the ability to arbitrarily move it around, and, if I can detect organelle touches, perhaps via CCSprites?

Community
  • 1
  • 1
Josh
  • 12,448
  • 10
  • 74
  • 118

2 Answers2

2

I recommend subclassing CCSprite and using your large image as the class's image. CCSprites certainly can detect touches by simply adding the basic CCTouchDispatcher delegate to the sprite's class:

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];

Then also add this method to your CCSprite subclass:

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event

You can do anything you want with the touches at this point, scroll or whatever suits your needs.

You could break up your image into many multiple sprites and use a CCLayer to manage touches instead, it just depends on whether you really need your image to be that large, or if the limitations for a single image are enough for you to work with, considering they are pretty large too. My method here is a lot less complicated than that.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
1

The max texture size is limited by OpenGL ES not just coscos2d and it changes by device. However, you can load the image into more than one texture and then position and move those textures around the screen. So really you could have the appearance of an image any size you would like but programmatically you will have to manage the different sprites (tiles) of the image.

CCSptites don't detect touches. CCLayers have will get the touch events you can then do a hit test to see if it hits a givcen CCSprite.

madmik3
  • 6,975
  • 3
  • 38
  • 60