Cocos2D - 大图
是否可以在 Cocos2D 中使用大图像,并允许用户通过滑动或捏合来放大和缩小?
我从这篇帖子中看到,Cocos2D图像的最大分辨率是2048x2048 。这显然比设备视口大,所以我希望用户能够在图像上移动。
我不是在创建游戏,而是在制作一种交互式生物细胞,它允许用户点击任意细胞器,并看到有关它们的信息的弹出窗口。
这是图像的一个想法,显然不可能将整个图像塞进设备视口中:
所以说真的,在我深入研究这个项目之前,我只是好奇是否可以使用大图像,让用户能够任意移动它,并且,如果我可以检测到细胞器的触摸,也许通过CCS精灵?
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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议对 CCSprite 进行子类化并使用大图像作为类的图像。 CCSprites 当然可以通过简单地将基本的 CCTouchDispatcher 委托添加到 sprite 的类来检测触摸:
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:selfpriority:-1 SwownsTouches:YES];
然后将此方法添加到您的 CCSprite 子类中:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
你可以做任何事情此时您想要进行触摸、滚动或任何适合您需要的操作。
您可以将图像分解为许多多个精灵,并使用 CCLayer 来管理触摸,这仅取决于您是否真的需要那么大的图像,或者单个图像的限制是否足以让您使用,考虑到它们也很大。我这里的方法比这简单得多。
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.
最大纹理大小不仅受 coscos2d 的限制,而且受 OpenGL ES 的限制,并且会因设备而异。但是,您可以将图像加载到多个纹理中,然后在屏幕上定位和移动这些纹理。因此,实际上您可以拥有任何您想要的图像外观,但您必须以编程方式管理图像的不同精灵(图块)。
CCSptites 不检测触摸。 CCLayers 将获取触摸事件,然后您可以进行命中测试以查看它是否命中给定的 CCSprite。
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.