Touch events

Touch events are really fundamental in a game where you are supposed to drag and drop tiles all over the place. I am very proud of the code I created in the Android version for the handling of touch events including logic wether an object can be dragged or not etc.

Naturally I wanted to have as much of that logic intact even in the iOS-version, otherwise I will have to start all over again with all testing. Now the problem is that AndEngine and Cocos2D handles touch events differently.

AndEngine is very kind to a developer since you can register touch events to an object meaning that AndEngine itself can figure out what you are touching and alert that specific object. In Cocos2D you can only register a touch listener to a complete layer. It’s then up to you to figure out yourself if / what object that was touched and alert it accordingly.

But I figured it out eventually. I made a few new subclasses, implemented a “isObjectTouched()”-function and am now sending the touch events to the tocuhed object meaning that I can reuse almost all of my existing logic regarding touch, drag and drop.

Now… if only the coordinate system hadn’t been upsidedown.

0 Responses to “Touch events”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: