I'm basically trying to move an overlay along a path as time moves along. This is how I'm doing it right now:
Imagine that this is all in an NSTimer with new values for position each time.
circle.position = (some moved position)
[overlay remove];
overlay = [smallMap addGroundOverlayWithOptions:circle];
And it basically works but introduces some flickering sometimes, which makes sense because one overlay is being deleted and a new one is added. Is there a function to actually change the position of an overlay without having to remove the old one and add a new one?
At the bottom of the this page it says:
If you wish to make modifications to an overlay after you've added it
to the map, ensure that you assign the overlay to an
id object when it is added.
So could you save the return value of addGroundOverlayWithOptions, and then update its position property later, instead of removing and adding the overlay again?
I haven't tried this, but it seems like it should work.
Related
How do I produce an animation that simulates the burning effect of fire consuming an UIView from top to bottom in Swift?
I found Fireworks, an app that allows users to tweak and try out different settings of CAEmitterLayer with instant results. The effects are great for applying to a whole screen but how would I use it for my purpose - where the UIView must disappear as the fire consumes it from one end to the other?
Is there some tutorial on consuming UIViews with fire using the particle emitter anywhere? I know that I’m supposed to show some code but anything I put here would be irrelevant. I’ve also exhausted my search engine looking for something similar. That’s how I found the Fireworks app actually.
This seems to be a use case that shouldn't be uncommon.
I haven't done much with CAEmitterLayer, so I decided to try my hand at this.
I created a project that does this an posted it on Github. It uses the approach in this Youtube video as a starting point. You can download it here:
FireEmitter project
Here is a small thumbnail of what it looks like:
The project includes a custom subclass of UIView called BurnItDownView
The BurnItDownView is meant to contain other views.
It has one public method, burnItDown(). That triggers the animation.
There are multiple parts to the animation:
A CAEmitterLayer set up to simulate flames burning off a flat surface:
An animation that lowers the emitter layer from the top of the view to the bottom,
A CAGradientView applied as a mask to the view that starts ot fully opaque (with colors of [.clear, .white, .white] and locations of [-0.5, 0, 1] (where the clear color is above the top of the view) and animates the locations property of the gradient view to mask away the view contents from top to bottom. (Animating the locations property to [0, 0, 0], so the entire gradient layer is filled with clear color, fully masking the view's layer.)
Once the view is fully masked, it starts lowering the "birthRate" of the emitter layer in steps until the birth rate is 0. It then holds this step for 2 seconds until all the flame particles have animated away.
Once the flame is fully "extinguised", it resets the locations array to the original value of [-0.5, 0, 1]. This causes an "implicit animation" so the view animates back from the bottom, but quickly
Finally, it resets the emitter layer and emitter cells back to newly a newly created emitter layer and emitter cell to get it ready for the next pass of the animation. (I couldn't figure out how to restore the emitter back to its original state. It was simpler to just create new ones.) It also invokes an Optional completion handler passed to the burnItDown() method. (The app's view controller uses the closure to re-enable the "Burn it down" button.
I was once in your shoe before and came across this Open source library called particle animations.
I would NOT recommend using the library itself since it's deprecated. But I would recommend referring to its source code to get an idea of how to use CAEmitterLayer and CAEmitterCell to make the looks of a Fire!
As you could see from its readme, it has direct examples of Fire. It also states that even Apple and Facebook uses CAEmitterLayer and CAEmitterCell to produce the effect of a fire.
Feel free to ask for more questions.
I have an NSTextView that users can type into. What's different is that I often make changes to the TextStorage while the user is typing in it (i.e. some information comes in over the network, and I need to represent that into the NSTextView by merging in these changes).
I can do that successfully - I've created a MovableCursor which keeps track of SelectedRange even when changes are happening behind the scenes.
I have this code working on iOS (UITextView) and the Mac (NSTextView). The problem is, on the Mac, the NSTextView usually jumps in the Scroller (i.e. the visible position in the View changes). It does not move at all on the UITextView - everything works perfectly, the cursor doesn't move in the window even though changes have happened to the TextStorage.
Simply using ScrollRangeToVisible doesn't work - it may make the Selection visible, but it necessarily make it visible in the same place.
I've tried grabbing the Scroller's VerticalScroller position, and then reapply it after making changes.
var scroll_pos = contentViewScroller.VerticalScroller.FloatValue;
...make changes...
contentViewScroller.VerticalScroller.FloatValue = scroll_pos;
Well, I can see the scrollbar doesn't move (expected), but the text still does. Somehow the scroller gets out of alignment with its position through the NSTextView. When I start moving the scrollbar, it seems to "flick" a little and get back in alignment.
So... Any thoughts on how I can make changes to an NSTextView's TextStorage, while keeping the Cursor (or SelectedRange) fixed in the same position on the screen.
[Note: of course there are times when this immobility is not possible - for example if everything before the cursor was erased, then the cursor must move to the top. That's ok.]
Many thanks.
How does one get a list (array) of currently visible overlay from a MapkitView?
Background - for example I want to show direction arrows to the center of certain Overlay types on my mapkitview, however how do I get the visible ones? There seems to be no way to do this I can see? So do I need to got through all overlays (actually ~8000) and do my own check to see what would be showing on the screen? Seems a waste if MapKit would have already effectively done this as part of deciding what overlays need to be displayed at a given time.
I've been tinkering with some similar problems and the most efficient way I could figure out was to add the overlays as annotations as well, since MKOverlay implements MKAnnotation. Then you would be able to use annotationsInMapRect for the currently displayed mapRect. However this would also return any regular MKAnnotations, and only uses the calculated middle of the overlay. The only way (so far as I figured) to only get the overlays would be to iterate over each overlay and use:
-(BOOL)intersectsMapRect:(MKMapRect)mapRect;
on the currently visible mapRect.
If you found another way I'd be happy to hear!
In xCode I'm making an iPad app, and have created a series of counters in UIimageViews that drag around the screen when you touch them. All good so far.
But now I want to have another smaller hidden button just above each counter that is disabled, so that when you tap on the counter the smaller button can appear and can perform an action (such as 'return to starting position' or 'hide'.
I'm just not sure where to go with this one now. Any ideas or hints would be much appreciated!
So you create the buttons and set their frames and add them as sub views to your view. From that point on you can hide them by making their alpha = 0.0, have them appear disabled by setting alpha to say 0.5 (set enabled to NO), and make them live with alpha=1.0. You can animate frame and alpha changes. For convenience you can set their tag properties to a value related to the counter so you can easily get them using viewWithTag:.
I don't understand how can I add images for order with corona sdk (front, top, middle). I mean like cocos2d I can add example [self addChild:bg z:-1]; [self addChild:nextSprite z:1]; [self addChild:secondSprite z:2]; etc. But there is no z:number value with corona sdk..
All what I have noticed is that when I add newImage it come top with previous newImage..do I have to done that with groups..or what..
I got this problem that when orientation change, background image change as well..but when the image change it hide all buttons..(=come top of screen and hides all other objects under)..
To give a specific answer, I solved this problem by creating initial groups and then adding images to those groups as needed.
local bgGroup = display.newGroup() -- renders first
local midGroup = display.newGroup()
local nearGroup = display.newGroup() -- renders last, over other groups
-- create images/etc
bgGroup:insert(backgroundImage)
midGroup:insert(houseImage)
nearGroup:insert(personImage)
As you found out, Corona does not have explicit z-ordering. Objects are displayed exactly in the order they appear in the group. You can re-insert an object at a particular index if you want to change the order it's drawn, but that's about it.
If you have a specific problem you're having trouble solving, I would recommend you post it as a separate question along with some sample source code. But in general, if you're adding a new image and you want it to go in back of existing images, simply use group:insert specifying an index of 1.
group:insert(1,backimage)
group:insert(2,middleimage)
group:insert(3,fontimage)
hope you got my point.
There are a few ways to solve zindex's in Corona SDK
1) The method you suggested where everything is in separate groups.
2) group:insert([int],displayObject) where [int] is the position you want the display object to render in the group. So 1 is on the bottom, 2 would be in the middle, and 3 would be on top.
3) You can use functions like displayObject:toFront() or displayObject:toBack() to re-position display objects. You can also re-insert the object into the same group to add it to the top, or even a new position (see method 2).
i would check out
Object.alpha = 0.8 (or whatever number you choose below 1.0)
basically you can make it appear in front of other objects it works fairly well.