How to move background in cocos 2d

时间秒杀一切 提交于 2020-01-29 05:34:05

问题


Hi i want to develop game like 'Doodle jump'.But i have some problem with the following features-

1.How to move background scene/image.

2.How to detect collision between object.Is it needed a physics engine like box2d or i should just use manual collision.

3.what should be the size of the background image.

4.In fact i have no idea how does background move .So i need a explanation from someone.


回答1:


  1. Background Movement A) You could create a TMX Tilemap and then make a very high Tiled-Map. B) You could create one texture and then cycle the texture coords instead of really moving it.

  2. Detect it manually. Best is detect it via "Point in Boundingbox" or "Rect in Rect". For more detail visit my blog entry for collision detection with cocos2d : http://www.anima-entertainment.de/?p=262

  3. Size of an Image Keep in Mind that textures are always at power of 2 in the memory. If you want to create one Background-Image at retina highresolution (960x640 Pixel) in the memory will be a texture of 1024x1024. If possible use smaller Background-Images and stretch them. (like 512x512). But I really would recommend for big scrolling images the TMX Support.

  4. CCTMXTiledMap * tmxNode = [CCTMXTiledMap tiledMapWithGMXFile:@"Level.tmx"];

    // lets say you want to move it 50 pixels down in 1 second :

    [tmxNode runAction:[CCMoveBy actionWithDuration:1.0 position:ccp(0,-50)];

    To create a tilemap : http://www.mapeditor.org/




回答2:


In the folder of cocos2d, you could get many demos of tilemap. TileMapTest.h TileMapTest.m




回答3:


refer this tutorial this will helpful for you.

http://www.raywenderlich.com/2343/how-to-drag-and-drop-sprites-with-cocos2d

this is used screen movement with pan recognizer



来源:https://stackoverflow.com/questions/4395959/how-to-move-background-in-cocos-2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!