Hi all,
I'm trying to do an open version of iSimulator, but targeted only for cocos2d and with the option to use the code base as a sort of controller for mac/ipad games.
Anyway, so far I've been able to inject touches without too much problem, but I'm loosing lots of them (for instance: I'm able to send a touch began, but the touch ended is sometimes lost, causing lots of trouble)
The way I'm doing it right now is this:
// this is some CCScene
- (id)init {
...
[[OpenSimSupport sharedOpenSimSupport] startListening];
...
}
The main loop opens a socket (only in the X86 platform) listening for the device to send commands. Right now, the only commands are touch events, but I can later add accelerometer and other events.
When an event is successfully parsed, it's inyected to the openGLView of the CCDirector like this:
- (void)process:(ProcessData *)pdata {
// check the first three characters for type of data
CC_GLVIEW *view = [[CCDirector sharedDirector] openGLView];
if (pdata.size > 3) {
// check if touch or acceleration
if (pdata.data[0] == 'T') {
if (pdata.data[1] == 'B' && pdata.data[2] == 'G') {
// touch began
NSSet *touches = [self parsePoints:pdata.data+4];
// call touchesXXX on the view
[view performSelector:@selector(touchesBegan:withEvent:) withObject:touches withObject:nil];
...
}
The listen loop is run in a background thread, but the process method is run on main thread.
Anyway... is this the best way to add touches? maybe I could just inject them directly to the CCTouchHandler?
@riq, what do you think?
[EDIT]: I think that the problem might be that I'm not linking a chain of touches with a UIEvent... maybe I should keep track of that.