Tuesday, 15 July 2014

Cocos2d iphone: changing CCSprite.position works on simulator but not on device -



Cocos2d iphone: changing CCSprite.position works on simulator but not on device -

i've got problem cocos2d code, runs fine on simulator (means in case sprites moving when touch , scroll) doesn't work on ipod cctouchesmoved called on both, sprite move in simulator

ccsprite *grada = [ccsprite spritewithfile:@"grad.png"]; grada.anchorpoint = ccp(0, 0); grada.position = ccp(0, 0); [...] -(void) cctouchesmoved:(nsset *)touches withevent:(uievent *)event { //nslog(@"cctouchesmoved called"); uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinview: [touch view]]; location = [[ccdirector shareddirector] converttogl:location]; int d = (_prevtouch.y - location.y); // code should create sprite moving // , on simulator not on ipod grada.position = ccp(paralax_x, grada.position.y - d); _prevtouch = location; } -(void) cctouchesbegan:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinview: [touch view]]; location = [[ccdirector shareddirector] converttogl:location]; _firsttouch = location; } -(void) cctouchesended:(nsset *)touches withevent:(uievent *)event { uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinview: [touch view]]; location = [[ccdirector shareddirector] converttogl:location]; _lasttouch = location; }

btw if "grada.position = ccp(0, grada.position.y - d);" in other method cctouchesmoved works on device , simulator.

it stupid error (and hope is) on side because it's first project.

here how moving sprites @ moment (in cctouchesmoved):

uitouch *touch = [touches anyobject]; cgpoint touchlocation = [self converttouchtonodespace:touch]; cgpoint oldtouchlocation = [touch previouslocationinview:touch.view]; oldtouchlocation = [[ccdirector shareddirector] converttogl:oldtouchlocation]; oldtouchlocation = [self converttonodespace:oldtouchlocation]; cgpoint translation = ccpsub(touchlocation, oldtouchlocation); cgpoint newpos = ccpadd(currentfragment.position, translation); currentfragment.position = newpos;

cocos2d-iphone ios-simulator ccsprite

No comments:

Post a Comment