Rotate element once it is selected flutter - animation

Recently I have created a post about how to rotate a dismissible element once it is swiped. I did get an answer so I decided to rewrite a question.
For example, I have a container with gesturedetector() widget, is it possible to scale it and rotate 5 deg.(duration like 5sec.) once it is tapped or longpress?

You might be interested in an AnimatedContainer which is a container that gradually changes its values over a period of time.
The duration of the transformation is controlled by specifying something like duration: new Duration(seconds:5) in the AnimatedContainer's constructor.
You can also specify additional transformations by for example scaling variables for the AnimatedContainer's width and height properties.
For more information, the flutter docs have a good intro to using AnimatedContainers.

Related

Unity3d: Camera Effects look different in different screen sizes

I have applied some post processing effects to my camera. They looked fine in the free aspect minimized game view but when I maximize it or change the aspect ratio the effects look different. And also how can I make my UI elements change as the screen size changes.
Images:
This is a bug in post processing stack and is still not fixed by them. But I found a fix here.
Fix:
open the DepthOfFieldComponent.cs, remove const from before k_FilmHeight, then have it update somewhere such as in Prepare, above CalculateFocalLength, add something like: k_FilmHeight = 0.024f * (Screen.height / 720.0f);
720 can be changed to whatever number you want to use as your default screen height.

Get Image clicked position on DIfferent Resolution when the coordinates will be changed on different devices

I have a responsive Image which is working on different mobile resolution.
I want to Ask you, when I clicked on image at any place like top-left, left-botton etc, I want to get its(image) position.Means On which position it is being clicked. I tried the following scenario While Implementation of my Source Code, I get a coordinate on particular place on which The image is clicked.
Problem: Each of Mobile device has different resolution, So, For the same scenario, the coordinate will be differed. I required the implementation like the place of clicked image should be same on every resolution.
please tell me how can I resolve my Issues, And which one is best technology, tell me if anyone has knowledge to resolve this.
There have been some previous posts that try to achieve what you want, the basic logic can be achieved by calculating ratio:
var xratio=225/420; // 420-mouse-x-coord divided by 420
var yratio=38/38; // mouse-y-coord/element height
var x=320*xratio;
var y=38*yratio;
Please see the following references:
How to convert click coordinates of different dimensions into 320 dimension size?
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

Unity 4.6 - How to scale GUI elements to the right size for every resolution

The new Unity 4.6 comes with a new GUI, when I change de resolution on Unity the UI Button scales perfectly but when I test on the Nexus 7 device the Button looks too small. Any idea how to solve this?
Unity's new GUI system uses "anchors" to control how gui elements (like buttons) scale in relation to their parent container.
Unity has a tutorial video on how to use the new "Rect Transform" component (where the anchors are configured) here: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.
The last half of the tutorial is all about anchors. That page has links to the entire tutorial series. It's not too long. You should watch the whole thing.
Specific to your question:
The anchors are visible in your first screen shot. They are those 4 little arrows at the top left of your button.
Right now, your button is only anchored by it's top left corner.
The two right anchors need to be dragged to the right so that the right edge of your button is anchored to a space inside its parent container.
Depending on your situation, the two bottom arrows may need to be dragged down so that the bottom edge of your button is anchored as well.
The video I linked above covers all this in detail.
Lastly, for the font size to scale nicely on different resolutions, you will need to add and configure a reference resolution component to the base canvas of your UI, as Ash-Bash32 wrote earlier.
Update: The best way to add a Reference Resolution component is through the inspector window for the base canvas in your UI.
1) click the "Add Component Button" at the bottom of the inspector.
2) type the word "Reference" in the search filter field.
3) select the "Reference Resolution" component in the search results.
The Reference Resolution is now renamed as Canvas Scaler.. Along with the renaming they have added many more features for the dynamicity of the Canvas. You can go through the Unity Doc of Canvas Scaler and also take a look at this article for a practical example of how and why to use Canvas Scaler. Also make sure you use the Anchor Points to good effect to make this more robust...
To Scale UI added the ReferenceResolution Component to the Canvas you want to scale.
P.S. Theres no Documention for ReferenceResolution
If you want the button to be the same size for all screens and resolutions, you have to add the canvas scaler component to the canvas and the set the screen match mode to: match width or height, here is the link to the docs, this helps a lot if you want to aim to different sizes or resolutions:
http://docs.unity3d.com/Manual/HOWTO-UIMultiResolution.html
This becomes giant and convoluted once you start laying things out in code AND using a canvas scaler, so I wish to provide a thorough answer to save someone the hours I went through.
First, don't use anchoredPosition to position anything, unless you fully realize it is a 0.0 to 1.0 number. Use the RectTransform localPosition to do the actual laying out, and remember it's in relation to the parent anchor. (I had to lay out a grid from the center)
Second, put a canvas scaler on the parent layout object AND the inner ui pieces. One makes the layout in the right position, the other will resize your elements so they actually show up right. You can't rely on the the parent unless the children also have scalers (and Graphic Raycasters to touch them).
Third, if you have a scaler, DON'T use Screen.width and height, instead assume the screen is the same value you put for the scalers (hopefully you used the same, or know what you're doing). The screen width always returns the actual device pixels, retina devices too, but the canvas scalers DO NOT account for this. This probably gives unity the one remaining way to find actual screen dpi if your game wants it. Edit: This paragraph applies to any parent canvas connected to the code doing your laying out. Not stray canvases, you can probably mix it up. Just remember unity's guidelines on performance with canvases.
Fourth, the canvas is still a bit buggy. Even with the above working, some things don't render until you delete and recreate a canvas, if you re-open the scene or it crashes. Otherwise, the above is the general "rules" I've found.
To center a "grid of things" you can't just use half of the canvas scaler's width or height, you have to calculate the height of your grid and set the offset by half of it, otherwise it will always be slightly off. I just added this as an extra tip. This calculation works for all orientations.

EaselJS and multi layered canvas system: performance tuning, game developing, event handling

I'm an engineer and we are currently porting our Red5 + Flash game into a Node.js + Easeljs html5 application.
Basicly: it's a board game, not an rpg. The layer system means we have multiple canvasses, based on functionally. For example there is a static background stage, with images. There is a layer for just the timers.
At default, all canvas size is 1920x1080, if needed we downscale to fit to the resolution.
The first approach used kinetic.js, but the performance fallen when the game got complex. Then we switched to easel, because it's abstraction level is lower, so we can decide how to implement some more function, not just use the provided robust one.
I was optimistic, but now it's starting to show slowness again, that's why I want to look deeper inside and do fine performance tuning. (Of course everything is fine in Chrome, Firefox is the problem, but the game must run smoothly on all modern browser).
The main layer (stage) is the map, contains ~30 containers, in each there is a complex custom shape, ~10 images. The containers are listening to mouse events, like mouseover, out, click. Currently, for example on mouseover I refill the shape with gradient.
Somehow, when I use cache, like the way in the tuts the performance get even worse, so I assume I'm messing up something.
I collected some advanced questions:
In the described situation when can I use cache and how? I've already tried cache on init, cacheUpdate after fill with other color or gradient, then stage.update(). No impact.
If I have a static, never changing stage cache doesn't make sense on that layer, right?
What stage.update() exactly do? Triggering the full layer redraw? The doc mentions some kind of intelligent if changed then redraw effect.
If I want to refill a custom shape with new color or gradient I have to completely redraw its graphics, not just use a setFill method, right?
In easel there is no possibility to redraw just a container for example, so how can I manage to not update the whole stage, but just the one container that changed? I thought I can achieve this with caching, cache all containers the just update the one that changed, but this way didn't work at all for me.
Does it make sense to cache bitmap images? If there are custom shapes and images in a container what is better? Cache the container or just the shape in container.
I found a strange bug, or at least an interesting clue. My canvas layers totally overlapping. On the inferior layers the mouseover listening is working well, but the click isn't on the very same container/object.
How can I produce a click event propagation to overlapped layers those have click listeners? I've tried it with simple DOM, jquery, but the event objects were far away from what canvas listeners wanted to get.
In brief, methods and props I've already played with bare success when tried tuning: cache(), updateCache(), update(), mouseEnabled, snapToPixel, clear(), autoClear, enableMouseOver, useRAF, setFPS().
Any answer, suggestion, starting point appreciated.
UPDATE:
This free board game is a strategy game, so you are facing a world map, with ~30 territories. The custom shapes are the territories and a container holds a territory shape and the icons that should be over the territory. This container overlapping is minimal.
An example mouse event is a hover effect. The player navigate over the territory shape then the shape is getting recolored, resized, etc and a bubble showing up with details about the place.
Basically, maximum amount of 1-3 container could change at once (except the init phase -> all at this time). Not just the animations and recoloring slow in FF, but the listener delay is high too.
I wrote a change handler, so I only stage.update() up on tick the modified stages and the stages where an animation is running (tweenjs).
In my first approach I put every image to the container that could be needed at least once during the game, so I only set visible flags on images (not vectors).
Regarding caching:
There are some strange caching-issues, somehow the performance can drop with certain sizes of the caching rectangle: CreateJS / EaselJS Strange Performance with certain size shapes
(2) Depending on how often you call stage.update();
(3)
Each time the update method is called, the stage will tick any
descendants exposing a tick method (ex. BitmapAnimation) and render
its entire display list to the canvas. Any parameters passed to update
will be passed on to any onTick handlers.
=> Afaik it rerenders everything if not cached
(4) Yes.
(5) No. (I don't know of any)
(6) If the content's of the container don't change often, I'd cache the whole container, otherwise the container will be reconstructed every frame.
I have a question though: Why do you use multiple canvases? How many do you use? I could imagine that using multiple canvases might slow down the game.
How many sprites do you use in total?
2: if your layer or stage doesn't change, don't call stage.update() for that layer (so it doesn't gets rerendered, gives me a much lower cpu!)
For example, keep a global "stagechanged" variable and set this to true when something has changed:
createjs.Ticker.addEventListener("tick",
function() {
if (stagechanged)
{
stagechanged = false;
stage.update();
}
});
(or do you already use this, as stated in your "update"?)
4: I found a way to update for example the fill color :)
contaier1.shape1.graphics._fillInstructions[0].params[1] = '#FFFFFF';
(use chrome debugger to look at the _fillInstructions array to see which array position contains your color)
5: I found a way to just paint one container :)
//manual draw 1 component (!)
var a = stage.canvas.getContext("2d");
a.save();
container1.updateContext(a); //set position(x,y) on context
container1.draw(a);
a.restore();

Frame based animation on WP7 Silverlight

Coming from the iOS world where we have UIImageView and the property animationImages:
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIImageView/animationImages
Where animationImages is just an array of arbitrary animation frames. You specify the images (maybe 15), then set the total animation time (maybe 4 seconds) in one of the other properties, then just start the anim and the images in animationImages will play sequentially over the specified time with an even frame rate.
How would I do the same with WP7/Silverlight? This all Expression Blend seems wonderful, but I just can't find a way to animate the image source (I'm guessing it might be impossible). How would I do the same? Should I add a unique image object for each frame in the animation, then play around with visibility/opacity properties and manually have to create all the spaced out key frames? That sounds like a lot of extra work + overhead and not a nice way to go...
http://www.windowsphonegeek.com/articles/WP7-Animations-in-depthndash-Overview-and-Getting-Started
http://www.wearerighteous.com/wp7-development/xaml-animation-in-silverlight-for-windows-phone-7/
http://www.windowspresentationfoundation.com/?p=712
Try out these links. Especially the first one, I think the first one resolve all you doubts. In wp7 we can go for two options either XAML based (static) animations / or with the help of C# code. By using blend u can create all sot of static animation with out any issue. Here the animation is working on the basis of page frames. If u are interested in learning more about Animation try this too;
http://msdn.microsoft.com/en-us/library/cc189019(v=vs.95).aspx
You can actually animate the Image.Source property here's a tutorial.
Animating Images in WP7

Resources