I'm currently working on a game for Windows Phone 7, using the XNA version of Cocos2d.
Due to the rules of the game, I need it so that the user can only touch one thing at a time but multitouch seems to be always in effect. Additionally I don't know if this is a Cocos error, but it also causes the game to behave erratically (responding to a single touch like they were many).
I guess I would have to correct every touch event of the game one by one, but I was wondering if I can use something to disable multitouch quickly, or reduce the number of touches accepted to one at a time.
I'm not sure about Cocos2d-x for XNA. But in regular XNA if you want to force only single-touch input, the simplest way to that is by using the Mouse class. In a touch environment it is still available - emulated by using touches. It only responds to a single touch at a time.
Each frame you can get the list of touches. Since their management is delegated to your code, just ignore them if you have more than one. Another option is only using the first one, remember its TouchID and ignore all the rest.
I've used the first option when porting mouse applications over to the phone.
Cocos touch input has to be treated somewhere in the game, in accessible code, so you should have access to their point of entry.
Yes, you can do this with Cocos2D-XNA. You set the TouchMode to be either OneByOne, or AllAtOnce. OneByOne will give you the single CCTouch signature methods, and AllAtOnce will get you the List signature methods.
public MyCtor() {
TouchEnabled = true;
TouchMode = CCTouchMode.OneByOne;
}
public override bool TouchBegan(CCTouch t) {
}
public override void TouchMoved(CCTouch t) {
}
public override void TouchEnded(CCTouch t) {
}
Now you only get one touch at a time. There's no way to disable the touch pad's delivery of all touches from all fingers though. As another user mentioned, you would just ignore those.
Remember that you get a touch ID with every touch, which works to match the touch data with each began, moved, ended event call. I suggest you make use of touch ID as well to ensure that you are processing only the touches that you want.
Related
I'm absolute beginner in UrhoSharp. I only wanted to implement some basic 3D stuff into my app. Everything works fine with SimpleApplication, the screen is supposed to be watched from one place and direction. When I touch the screen, the scene rotates however. How can I get rid of this behavior?
I wanted to try to override some function of SimpleApplication (probably OnUpdate) so I came with name CursedApplication replacing SimpleApplication everywhere. When I use
using CursedApplication = Urho.SimpleApplication;
everything still works. But what I supposed to be the equivalent
class CursedApplication : Urho.SimpleApplication
{
CursedApplication(ApplicationOptions options) : base(options)
{
}
}
breaks the application. Some idea how can I make things work? Or do I have to build my own scene logic without SimpleApplication?
Finally I found that this can be done with
app.Input.Enabled=false;
where app is instance of SimpleApplication.
I'm working on the RN application that has one screen with a list of "drawable" areas in it. So this screen should be scrollable AND drawable.
What I'm trying to do - is to find a solution to distinguish touch events coming from fingers (these will be used to scroll and disallow drawing) and stylus via Apple Pencil (these will be used to draw and disallow scrolling).
In both Gesture Responder and PanResponder there are events being passed on each move. Each of those events (alongside with the nativeEvent) contains the type property. However, it's always null for me in both simulator and device.
Is there any way to recognize a move event as a finger vs stylus?
We had a similar requirement for one of our projects, and what we did was to use a Pressable component, to which a handlePress function was passed as prop.
This function accepted the GestureResponderEvent as event callback argument.
By using the event.nativeEvent.altitudeAngle property that was added recently, we were able to detect Apple Pencil touches.
function handlePress(event: GestureResponderEvent) {
//#ts-expect-error React Native Types do not include altitudeAngle
const isPencilTouch = !!event.nativeEvent.altitudeAngle;
...
}
I'm currently trying to make my game become more accessible by adding VoiceOver support. Everything is working fine on iOS, but I have some struggle with the watchOS Version. I need a way to find out, if VoiceOver is currently enabled to remove certain images based questions in the game. So ist there anything like:
UIAccessibilityIsVoiceOverRunning()
in WatchKit?
And also, is it possible to move the accessibility focus to a certain element? Something comparable to:
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, view);
Thanks, Klemens
To check if it's running
let isVoiceOverOn: Bool = WKAccessibilityIsVoiceOverRunning()
if isVoiceOverOn {
// do some VoiceOver stuff
} else {
// do some stuff that does not make sense for VoiceOver
}
To find out when VoiceOver starts and stops observe:
WKAccessibilityVoiceOverStatusChanged
I am making an iOS game and I need a detection for both simple tapping and gestures (swipe etc) simultaneously. In AIR, I can only see one setting for the Multitouch input mode: TOUCH_POINT (which works for basic tapping) and GESTURE. But I need both at the same time so changing the mode isn't an option. How can I listen to both at the same time?
Thanks,
Can.
import flash.events.EventDispatcher;
import flash.events.TouchEvent;
import flash.net.Responder;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class SwipeAndTap extends EventDispatcher
{
private var fingerX:int;
private var fingerY:int;
private var elem:Object;
public function SwipeAndTap(_elem:Object)
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
elem = _elem;
elem.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
elem.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
elem.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}
private function onTouchBegin(e:TouchEvent):void
{
fingerX = e.stageX;
fingerY = e.stageY;
}
private function onTouchMove(e:TouchEvent):void
{
if(e.stageX > (fingerX+150) && (e.stageY > (fingerY-100) && e.stageY < (fingerY+100) ) )
{
// swipe right
dispatchEvent(new TouchSwipeRight(TouchSwipeRight.SWIPE_RIGHT, e));
}
else if(e.stageX < (fingerX-150) && (e.stageY > (fingerY-100) && e.stageY < (fingerY+100) ) )
{
// swipe left
dispatchEvent(new TouchSwipeLeft(TouchSwipeLeft.SWIPE_LEFT, e));
}
}
private function onTouchEnd(e:TouchEvent):void
{
// e.touchPointID;
if(e.stageX > (fingerX-40) && e.stageX < (fingerX+40))
{
dispatchEvent(new TouchEventTap(TouchEventTap.TAP, e));
elem.removeEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
elem.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
elem.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}
}
}
Example:
var SAT:SwipeAndTap = new SwipeAndTap(stage);
SAT.addEventListener(TouchEventTap.TAP, LangSelected);
SAT.addEventListener(TouchSwipeRight.SWIPE_RIGHT, ENtoPL);
SAT.addEventListener(TouchSwipeLeft.SWIPE_LEFT, PLtoEN);
You can use standard mouse events for tap.
This would maintain gesture multitouch input mode.
Otherwise, Gestouch framework: NUI gestures detection framework for mouse, touch and multitouch AS3 development at GitHub might be of interest.
Also note performance impacts of touch / gesture event model:
Both touch and gesture input can be multitouch input depending on the
user’s device. ActionScript provides API for handling touch events,
gesture events, and individually tracked touch events for multitouch
input.
Note: Listening for touch and gesture events can consume a significant
amount of processing resources (equivalent to rendering several frames
per second), depending on the computing device and operating system.
It is often better to use mouse events when you do not actually need
the extra functionality provided by touch or gestures. When you do use
touch or gesture events, consider reducing the amount of graphical
changes that can occur, especially when such events can be dispatched
rapidly, as during a pan, rotate, or zoom operation. For example, you
could stop animation within a component while the user resizes it
using a zoom gesture.
I'm not quite sure if you need to set TOUCH_POINT for basic tapping. It should work just as well if you've got GESTURE set. You can simulate it with mouse events.
At any rate, the default AIR gesture support isn't that good anyways, so it might not work that way, hence I'd recommend looking into the Gestouch library. You get much more sophisticated gesture support that work very well. I've been using it in my Flex/AS3 projects for many month now and I'm quite happy with it.
I'm working right now on an iOS project with air. Everything is fine, and I implemented the "swipe" gesture among some others. In the beginning, the gesture was recognized, the event fired, everything alright.
Then I changed something (don't ask me what), and the event isn't any more dispatched.
So my Problem is, if I want to test it, I'll have to compile, then upload to testflightapp.com, then install it. Takes a lot of time.
Is there any possibility to test the gesture on my mac while developing? So I can trace and check what is happening, or what not.
I compile with the Flash IDE CS5.5, but could also with Flash Builder if there is a solution.
And just for your interest, here the interesting part of my code.
Multitouch.inputMode = MultitouchInputMode.GESTURE;
contestView.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipeContest);
function onSwipeContest (e:TransformGestureEvent):void{
if (e.offsetX == 1) {
//User swiped towards right
// do something
}
}
This is a lame answer, but why aren't you skipping the testflight step and just dumping it straight to your phone? do you have xcode installed? if so, fire it up, open the organizer, set your device for development, and have at it. way, way faster that way.
anyway.
are you sure that gesture events aren't functioning on your mac? i've found that multitouch events are spotty, but gesture ones usually work ok on the trackpad from air 2 onward.