iphone - Loading and Unloading background images as game moves -
hey guys, have raidan style 2d flying/fighter game im working on. upon moving standard nsobject framework cocos2d, have encountered issue background image/sprite.
before cocos2d, background large vertically. 320x9999 (or something). loaded , created illusion large level. cocos2d has limitations on image sizes, forced slice image 33 different background images each @ 320x480.
understanding memory big deal on ios platform, decided create 2 background ccsprites: ccsprite *background1, *background2; background2 ontop of background1.
using these 2 backgrounds, jet moves screen, each background move inversely down screen @ equal rate, first background1 moves off screen vertically, released memory , new sprite loaded background1 , background1 positioned above background2 vertically.
as background2 moves off screen, released , new image loaded background2 , placed ontop of background1.
creating illusion of constant , consistent background.
q. seem valid method? q. how go achieving programatically? have physics of movement , ready go. im little unsure how cocos.
once again, in advance!
a1) yes it's valid way so, , it's easy thing ht ecode goes somthing (i may have programatical errors ,consider psudo code!):
if(background[1].position.y < 0) { [layer removechild:background[1] cleanup:yes]; background[1] = background [2]; background[2] = [ccsprite spritewithfile:"file id"] background[2].position = ccp(0,480); [background[2] runaction:[ccmoveby actionwithduration:1 position:ccp(0,1)]] }
a2) if needed guide gave implementation need , if mean don't know how implement plysics stuff using cocos2d-iphone try these manuals :
http://www.raywenderlich.com/457/intro-to-box2d-with-cocos2d-tutorial-bouncing-balls
Comments
Post a Comment