Note that there are some explanatory texts on larger screens.

plurals
  1. POBlock of code running in iPhone simulator and not on iPhone 4? (COCOS2D)
    primarykey
    data
    text
    <p>I am using the ccTouchBegan and ccTouchEnded, and for some reason there is a block of code that runs perfectly on iPhone simulator and doesn't run at all on iPhone 4. This is what my methods look like:</p> <pre><code>-(BOOL)ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event { firstTouch = [self convertTouchToNodeSpace:touch]; if (!self.currentFootball.footballHasEmbarked) { //arrow.position = ccp(fPos.x, fPos.y); float newAnc = (120 + (self.currentFootball.contentSize.width * .5f) + (arrow.contentSize.width * .5f)) / arrow.contentSize.width; arrow.anchorPoint = ccp(-newAnc, .5);//self.currentFootball.position; arrow.position = self.currentFootball.position;//ccp(fPos.x-120, fPos.y); arrow.rotation = 180; arrow.visible = YES; arrow.scale = 0.5f; //powerLevel.position = fPos; powerLevel.position = self.currentFootball.position; powerLevel.rotation = 180; powerLevel.percentage = 0; powerLevel.visible = YES; outLine.position = self.currentFootball.position; outLine.rotation = 180; outLine.visible = YES; CCProgressFromTo *powerBarGoUp = [CCProgressFromTo actionWithDuration:1.0f from:0.0f to:100.0f]; CCProgressFromTo *powerBarGoDown = [CCProgressFromTo actionWithDuration:1.0f from:100.0f to:0.0f]; id action = [CCRepeatForever actionWithAction:[CCSequence actions:powerBarGoUp, powerBarGoDown, nil]]; [powerLevel runAction:action]; return YES; } else { return NO; } </code></pre> <p>}</p> <pre><code>-(void) ccTouchEnded:(UITouch*)touch withEvent:(UIEvent *)event { const float max = 100; CGPoint endTouch = [self convertTouchToNodeSpace:touch]; if (endTouch.x &gt; firstTouch.x) { endTouch = ccp(firstTouch.x, endTouch.y); //CCLOG(@"I ran"); } arrow.visible = NO; powerLevel.visible = NO; outLine.visible = NO; self.currentFootball.footballHasEmbarked = YES; self.currentFootball.spiraling = YES; if (self.currentFootball) { [smgr addBody:self.currentFootball.body]; } if (CGPointEqualToPoint(endTouch, firstTouch)) { CCLOG(@" I have run"); float anchorPointDist = ccpLength(endTouch); float distFactor = distFromFb + anchorPointDist; projectionAnchorPoint = ccp(firstTouch.x + distFactor,firstTouch.y); } CGPoint diff = ccpSub(endTouch, projectionAnchorPoint); float len = powerLevel.percentage; CGPoint norm = ccpNormalize(diff); if (len &gt; max){ len = max; } [self.currentFootball applyImpulse:ccpMult(norm, (len * 300))]; pos = self.currentFootball.position.y; [self schedule:@selector(newFootball)]; </code></pre> <p>}</p> <p>This is the block of code that will not run on my iPhone.</p> <pre><code>if (CGPointEqualToPoint(endTouch, firstTouch)) { CCLOG(@" I have run"); float anchorPointDist = ccpLength(endTouch); float distFactor = distFromFb + anchorPointDist; projectionAnchorPoint = ccp(firstTouch.x + distFactor,firstTouch.y); } </code></pre> <p>Am I not doing something right?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload