Detect Swipe Direction in cocos2d-x - cocos2d-x

Detect Swipe in Cocos2d-x.
How can we find the direction of swipe using CCSwipeGestureRegognizer.
Find whether we swipe left or right direction on the screen.

Taken from its documentation ( link ) :
In your callback method you should receive a CCObject* parameter, which should be cast to CCSwipe* which has a public memeber CCSwipeGestureRecognizerDirection direction; which I believe is what you need.
Let me know if anything is not clear.

If you have used CCSwipeGestureRecognizer then you have added some target method
for example if your target method is Swipe_Action then you will get direction using following code
definition of your method should be
void yourclassname::Swipe_Action(CCObject *object)
{
//get swipe type
if(((CCSwipe*)object)->direction==kSwipeGestureRecognizerDirectionRight)
{
//your code here
}
}
you can put condition for different swipe type for different result.. hope this helps
Let me know if this dont work.

Related

Map pinning in react native

I am looking for a way to capture user click and create a pin on the map view. Does anyone has any idea where can I start, I was not able to find anything.
There are two solutions for your issue.
Using RN's native MapView component, there are no easy solutions. You can create a pin when `onRegionChangeComplete is triggered. But you'll get the coordinates of the center of the map only. I've set up a running example for you here.
You can use this very well done package. In this package, there is an onPress method that you can use. It'll return you the coordinate of the point you just pressed.
You should look at the onRegionChange prop from the MapView component. That's a function that will be triggered whenever the user drags the map. Between that and the annotations props you should be able to achieve what you want.

Unity JavaScript OnCollisionEnter with 2D gameObject

Im trying to destroy a gameObject (in my case a 2d ball) when my player comes into contact with it with the built-in OnCollisionEnter function. My script is only attached to the player. Both the player, and the ball(battery) have 2d box colliders, and rigidbodies. Perhaps the fact that they are 2d colliders instead of regular has something to do with the problem? Ah! yes I almost forgot to mention the problem; it's not working. Its niether destroying, or printing "hit".... and oh yes, i DID name the ball "battery". thAnks so much I would very much appreciate some help!
UnityScript Code:
function OnCollisionEnter(batt : Collision)
{
if(batt.collider.name == "battery")
{
Destroy(batt.gameObject);
Debug.Log("Hit");
}
}
if you are using unity's 2d toolset, instead of OnCollisionEnter you use OnCollisionEnter2D, and inside the variables, instead of batt: Collision, you need to change it to batt: Collision2D, hope this helps :), also, you said your both objects have 2d box colliders and rigidbodies, make sure it's a 2d rigidbody and not a 3d rigidbody (default)
Well, its hard to debug collisions in Unity, and even harder without knowing your whole project. But a few things:
1) Make sure you have rigidbodies attached to your gameObjects that you want to receive events
2) For your code I'm not too sure ( since I mostly do C# ) but basically:
OnCollisionEnter( Collision batt ){
if ( batt.gameObject.name == "battery" ){
//Do what you want it to do
}
}
I think essentially you might not be pulling in the right name. If that doesn't work, try to place a debugger breakpoint on the OnCollisionEnter to see if it is being called.

Metro App OnSearchActivated ProgressRing not displaying

I am implementing searching within my Metro application. The search works well, results and UI come up as expected with one problem though.
I try to display a ProgressRing before the search and hide it after the search completes, but it never gets displayed.
What am I missing, code snippet below:
protected override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
{
// Some Metro designer generated code here
// Show progress ring
MainPage.Current.ResetProgressRingState(true);
// Bind search results
MainPage.Current.BindSearchResults(args.QueryText);
// Ensure the current window is active
Window.Current.Activate();
// Hide progress ring
MainPage.Current.ResetProgressRingState(false);
}
I suspect that the BindSearchResults method needs to be awaited in order for the ProgressRing to work correctly. If so, what's the easiest way to make that method awaitable, if not please advise what I am missing here.
If so, what's the easiest way to make that method awaitable, if not please advise what I am missing here.
Mark it as async and have it return Task. Within that method, use await on other asynchronous operations.

How can you use popView in a view navigator app to return to the previous view?

Obviously poptoFirstView returns the user to the firstView. But say I want to just return to the previous? Yes, I know the user has the back button on their mobile device. But for usability sake. Someone said you can use popView to return to the latest one. But gave no hint of how to do so.
enter link description herepopView()was the hint!
If you don't know how to use methods, you should always first refer to the AS3 reference, in your case the part about the ViewNavigator's popView() method: AS3 ViewNavigator

How to get the ContextMenu Target in Flash

in a flash application i have to build i would like to find out what the target of the context menu is, which gets displayed when i ctrl-click.
the reason for that: i created a custom context menu, which only displays over a certain area of the Sprite it belongs to. so there seems to be something "blocking the way".
any ideas? thanks!
Have a look here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/ContextMenuEvent.html#ContextMenuEvent()
to get the target of a ContextMenuEvent you want to access the mouseTarget property of that event.
The best way to debug this is using a click handler at the stage level.
stage.addEventListener(MouseEvent.CLICK, stageClickHandler, true,
int.MAX_VALUE, true);
Set useCapture to true so no other object can "swallow" the event, and priority to int.MAX_VALUE for good measure.
In your stageClickHandler():
private function stageClickHandler(event:MouseEvent):void
{
var targetObject:DisplayObject = event.target;
trace("click target", targetObject);
}
Now click on the area that isn't displaying the context menu (when you expect it to), and see what is printed in the log file. You can do some inspection on targetObject by checking its name property, its parent, and so on.
Hope this helps.
take a look at at the contextMenuOwner property of the contextMenuEvent ;)