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.
Related
I have a problem in my iPhone app when trying to instantiate an ARSCNView again, after destroying it.
In my ViewController I programmatically create an ARSCNView for motion capture interaction:
func addARSceneView() {
arSceneView = ARSCNView(frame: self.view.frame)
arSceneView.loops = true
arSceneView.session.delegate = self
self.view.addSubview(arSceneView)
arSceneView.session.run(ARBodyTrackingConfiguration())
}
When the user leaves this part of the app, I tear it down like this:
func removeARSceneView() {
arSceneView.session.pause()
arSceneView.pause(self)
arSceneView.session.delegate = nil
arSceneView.removeFromSuperview()
arSceneView = nil
}
Later, when I try to instantiate an ARSCNView for the second time using the first function above, it crashes with an EXC_BAD_ACCESS in the constructor:
I also tried to use a view from a xib which contains an ARSCNView but the same problem occurs, in that case in the init(coder) function of that view.
I found nothing on this problem, I guess usually developers only create an ARSCNView once.
TLDR: Turn "Metal API Validation" on in your scheme.
I found the culprit, after creating a sample project with only the ARSCNView, which did not have this problem. I started by stripping everything away from my original project until it was as barebones as the sample. That did not solve it, so I compared every little setting of the two, and behold: in the "Run" scheme of the original project, under "Diagnostics", I had "Metal – API Validation" ticked off. I don't remember when and why I did that; I assume it was some attempt to improve performance at one point. However, enabling this checkbox solved the problem completely.
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.
Is anyone able to actually make it work properly in Flex SDK 4.6?
Here's a short snippet :
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
addedToStage="onAddedToStage(event)"
title="Title">
<fx:Script>
<![CDATA[
private function onAddedToStage(event:Event):void {
if (stage.autoOrients) {
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging, false, 0, true);
}
}
private function orientationChanging(event:StageOrientationEvent):void {
if (event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN) {
event.preventDefault();
}
}
]]>
</fx:Script>
</s:View>
What I'm trying to achieve is to support Landscape mode in both orientations, so if user turns the device 180 degress, the screen should also rotate. But there should be no action at all, when user rotates the device to one of portrait orientations. Instead, I'm seeing width changes to navigator action bar and sometimes content in portrait orientations, so apparently preventing the event is not enough. I'm using the "official" way Adobe suggests, but the problem is that it's not working very well. Granted, the stage does not change, but it seems that there's something firing in navigator anyway, since you can see the action bar width changing.
I had some success with explicitly setting layoutbounds to fixed width in handler method - this prevents changing the actionbar width, but it's only a temporary solution - if the view is a subject to a transition, or some other redraw - it will again render with bad sizes. As if there was something below that was telling it that it's in portrait mode, even though I'm trying to prevent it.
Before you detonate with some silly ideas like "autoOrient = false", don't. It's clearly not a solution for this problem. Obviously it's a bug with Flex SDK - did anyone find a way to fix it or a stable workaround?
EDIT: apparently others bumped into similar issue:
- http://forums.adobe.com/message/3969531 (the main topic is about something else, but read magic robots's comment)
- http://forums.adobe.com/message/4130972
I'm not sure if this is the right one, did I do something wrong in the end, but after a lot of struggle, I've found this one to be stable solution:
private function onAddedToStage(event:Event):void {
if (stage.autoOrients) {
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging, false, 100, true);
}
}
private function orientationChanging(event:StageOrientationEvent):void {
event.stopImmediatePropagation();
if (event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN) {
event.preventDefault();
}
}
First thing to note is that addedToStage fires few times (2-3) in mobile application. I don't know why, there's no addChild in my code, obviously. Maybe the AIR runtime does something else. So, to avoid adding unnecessary amount of handlers, the common technique is to remove handler first - it won't do anything, if such handler is not yet registered, but if there is, it will remove it, which will maintain the handler count on 1.
Second thing is the priority of the event - it won't work on 0, it has to be set on something big, to launch before stuff in AIR runtime.
Last thing - event.stopImmediatePropagation() - now, that we're the first to handle the event, we cant prevent this event to be sent further up in this particular scenario.
This together makes the orientation preventing working perfectly - for me the landscape and the reversed landscape (rotated_left, rotated_right) were working and transitioning, while portrait modes did not affect the view at all.
Now, there's danger here - you might want to remove the listener upon leaving the view (on transition animation end, view deactivate or something), because stopImmediatePropagation will prevent the event to be handled in other parts of your application.
I hope Adobe (or Apache now, actually) will take a closer look at this problem and trace my solution.
EDIT
There remaisn a last issue with this solution, which is if application starts while device is in DEFAULT or UPSIDE_DOWN orientation, in this case application will be in portrait mode.
To fix this, a solution is to change Aspect Ratio within addedToStage handler:
if(Stage.supportsOrientationChange) {
stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
}
So I had the same problem you had. I think I finally figured out the solution. Heres what I did:
<s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
...blahblahblah...
width="1024"/>
protected function tabbedviewnavigatorapplication2_applicationCompleteHandler(event:FlexEvent):void {
stage.autoOrients=true;
preventOrient();
}
private function preventOrient():void {
if (stage.autoOrients) {
stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChanging, false, 100, true);
}
}
private function orientationChanging(event:StageOrientationEvent):void {
if(event.afterOrientation == StageOrientation.DEFAULT || event.afterOrientation == StageOrientation.UPSIDE_DOWN || event.afterOrientation == StageOrientation.UNKNOWN) {
event.preventDefault();
}
}
Worth noting is that in the application complete handler I set stage.autoOrients to true because in the app.xml file I have it set to false, due to having a splash screen and not wanting users to re-orient the screen during that time. Really the only thing I did different is account for the StageOrientation.UNKNOWN and prevent whatever that would do, set the width to 1024(for the iPad screen, might be different for other tablet devices) in the main mxml file, and removed the stopimmediatepropagation. Hope this helps.
I've recently started checking out XNA. All is going well and I've even got a working sample started. One thing that's been bugging me is that whenever I place my mouse over the game window it disappears. I don't know if this is the default behavior but I would like to change this so that I can see my mouse. Any and all advice is appreciated.
Simply set IsMouseVisible to true in your main game class(preferably in your Initialize method or Game class constructor) :
IsMouseVisible = true;
I'm pretty new to MonoTouch and I'm having problems getting my app to rotate from portrait to landscape mode.
My project has two XIB files, the MainWindow added by MonoTouch and MainController.xib which I have added. The MainController has a single label and no other controls. In my Main.cs I have the following to load the MainController.xib file:
UIViewController controller = new MainController();
window.AddSubview(controller.View);
In the MainController code I added
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return false;
}
It all runs fine and the label displays but when I rotate the simulator nothing rotates. I'm sure it's something really simple that I'm getting wrong but I just can't seem to crack it.
Any help would be appreciated.
You can look at TweetStation for a sample.
In this particular case, you might want to return "true" instead of false in the sample above.