달력

10

« 2024/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
http://www.cocos2d-iphone.org/forum/topic/5270#post-31812

Hey guys and gals, just let y'all know ahead of time that I have an updated version of my gesture detection class that I am about to release in the next several days.

One, it fixes several bugs.

Two, it is now a singleton, which means you now just call [Gestures sharedGestures] to access the object.

Three, it now uses delegates for when a gesture is detected. To set the delegate to call you do [Gestures sharedGestures].delegate = self or any other object that implements the Gestures Delegates. I will have further instructions on how to set it up when I release it in the coming days.

Four, the delegates are all optional, meaning you do not have to implement all of them if you only want to use one of them. The class automatically checks to see if the delegate method is available before calling it.

Five, it now only stores one array of points for all classes, which means it uses less memory. Also, due to that it now will check against all different types of gestures at the same time and send a delegate response to the ones detected. However, there may be a slight concern if you implement the special circle, x, or square gestures and a sliding gesture, because both may be detected at the same time.

Six, it now how has helper functions for calculating velocity for X and Y for two specified points based on a certain travel time. I implemented this because I found I needed it when using chipmunk physics engine to move objects to certain points within a given time frame. The functions are separated into one for X Velocity and Y Velocity, so you know how much to apply for the cpVect for both x and y. Technically, this should work just fine with box2d also, because it uses the standard acceleration physics formula between two points in a given time.

Finally, here is the updated version of the gesture class:

http://www.vantagetechnic.com/programming/iphone/Gestures.zip

Here are examples on how to use the class functions and delegates:

How to setup the GestureComplete Delegate:

@mojo - Yes - and Metric was kind enough to share the following code with me:

-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
	CGPoint point = [touch locationInView: [touch view]];
	CGPoint converted = [[CCDirector sharedDirector] convertToGL:point];

        //Do something on moved with object

        //Add point to the Gestures point buffer
        [[Gestures sharedGestures] addPoint:converted];
}

This is a very good i just find that the gesture are firing over and over again

and the default values don't seem to work any one fancy sharing there settings for circles squares and x?

these were the only things i tweaked for circle on the iPad:

//anything longer than 2 seconds and...well that's just not fast enough
[Gestures sharedGestures].circle.maximumCircleTime = 2.0;
//being a bit more generous since i only really want circle to work
[Gestures sharedGestures].circle.circleClosureDistanceVariance = 160.0;




:
Posted by netkorea