ios - CCLayer scaling and touch implementation? -


i've made cclayer holds ccsprite , 2 cclabelbmfont's. goal create customized "button" scale down when pressed. i've ran problems touch , scaling of layer.

first touch, can't touch layer bounding box accurately if convert touch this:

cgpoint currenttouchlocation = [self converttouchtonodespace:touch]; 

touch handled this:

// touching shop item? if(cgrectcontainspoint([self boundingbox], currenttouchlocation)) {     nslog(@"pressing item");     mshopitempushed = true;     return true; }  return false; 

seems there no realistic size boundingbox cclayer it's contents default figure need overwrite 1 based on cclayer contents? ideas how can correctly?

second problem scaling of cclayer based "button". if touch handling work somehow, scaling layer down half causes scaled layer move off tens of pixels original position. there no anchors set still moves layer quite bit side , when scaling. how can prevent behavior?

here code of cclayer based button:

+(id) shopitem:(nsstring*)filename : (cgpoint)position : (nsstring*)itemname : (int)itemprice {     return [[[self alloc] initwithshopitemdata:filename:position:itemname:itemprice] autorelease]; }  -(id) initwithshopitemdata:(nsstring*)filename : (cgpoint)position : (nsstring*)itemname : (int)itemprice {     self = [super init];     [self setposition:position];      mshopitempushed = false;      mpicture = [ccsprite spritewithspriteframename:filename];     [mpicture setposition:cgpointmake(position.x - (3.0f * [devicespecific cellsize]), position.y)];     [self addchild:mpicture z:1];      // make price string     nsstring* price = [nsstring stringwithformat:@"%d", itemprice];      mitemprice = [cclabelbmfont labelwithstring:price fntfile:[devicespecific scoreandcoinfont]];     [mitemprice setscale:0.5f];     [mitemprice setanchorpoint:cgpointmake(1.0f, 0.5f)];     [mitemprice setposition:cgpointmake(position.x + (3.5f * [devicespecific cellsize]), position.y)];     [self addchild:mitemprice z:1];      mitemname = [cclabelbmfont labelwithstring:itemname fntfile:[devicespecific scoreandcoinfont]];     [mitemname setscale:0.5f];     [mitemname setanchorpoint:cgpointmake(0.0f, 0.5f)];     [mitemname setposition:cgpointmake(mpicture.position.x + [devicespecific cellsize], mpicture.position.y)];     [self addchild:mitemname z:1];      self.istouchenabled = yes;      return self; } 

the [devicespecific cellsize] measuring unit keep distances correct on different devices.

i solved overwriting boundingbox -function rect based on outer limits of items in layer. scaling problem remained made indicator received touches.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -