Is there a way to track messages up the chain beyond cocos libraries? I want to see where x is getting set to zero (y is not), and the earliest I can place a breakpoint is EAGLView, where it is already 0. I'd post code, but I'm afraid I haven't a clue where the issue is to begin with. I shuffled all of my code, and I'm not doing much differently than a different scene that runs perfectly. I do use a tile map, but it is as a child, and shouldn't result in this.
Touch returning x=0, y correct, for all touches.
(7 posts) (3 voices)-
Posted 1 year ago #
-
Don't know if this might be your problem too but I just dug through for two days a nightmare I thought was a memory problem. But it turned out you can't rely on auto initialization of local variables. In my case two booleans in one function would sometimes initialize to false other times not. It created such strange non deterministic behavior.
If I'm guessing your code correctly, try implicitly setting to CGPoint pt = CGPointZero rather than assume it will correctly do it for you.
Posted 1 year ago # -
I don't believe that's it, but that's always a good reminder! The touches are coming from outside my code, with x = 0 already. I imagine the issue is in my code, but I'm not generating x itself.
I've reduced it to the following, perhaps someone will notice something obvious:
#import "STTempScene.h" @implementation STTempScene @synthesize mainLayer = _mainLayer; +(id) scene { STTempScene *scene = [STTempScene node]; STTempLayer *mainLayer = [STTempLayer node]; scene.mainLayer = mainLayer; [scene addChild:mainLayer]; return scene; } @end @implementation STTempLayer -(id) init { if( (self=[super init] )) {} return self; } - (BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint portraitPoint = [touch locationInView: [touch view]]; CGPoint touchPoint = CGPointMake(portraitPoint.y, portraitPoint.x); return YES; } - (void) dealloc { [super dealloc]; } -(void) registerWithTouchDispatcher { [[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:3]; } @endand
[[CCDirector sharedDirector] runWithScene:_thisTempScene]; self.thisTempScene = [STTempScene scene];in my delegate. The normal initializing applies, and I'm using a view controller.
Posted 1 year ago # -
Where do you print values of x and y?
Posted 1 year ago # -
I'm using several breakpoints and reading the touch directly. Even in EAGLview it is 0 (but y is correct), for all touchesBegans.
Posted 1 year ago # -
Issue resolved:
At some point I accidentally edited the data formatter for CGPoint, fromx = %x%, y = %y%tox = 0, y = %y%in the debugger, and didn't notice. Ugh. If I had done what jd asked about, I would have discovered the debugger was not reading the values correctly (touch.x was correct).Posted 1 year ago # -
Usually when I see this issue, it's somebody using %s to print a int or float so I figured I would check. Glad you found it.
Posted 1 year ago #
Reply
You must log in to post.