Here is my problem: I developed an App that split fairly teams for a soccer game. It also can count the goals of each player. The player that makes a goal has his level up. I want an animation that shows the star been filled. How can I do this?
Depends on the way you want your animation to look like.
My suggestion is to make a empty star (just a border) and make it full size. Then add another on top of it (thats filled).
Before the animation starts you need to resize that star so it's nonexistent (width and height are zero)
filledStar.transform = CGAffineTransformMakeScale(0, 0)
and then animate it to full size like this
UIView.animateWithDuration(0.5) {
filledStar.transform = CGAffineTransformIdentity
}
You can also play around with spring animations so it over extends and then goes to full size, but that is up to you.
Treat the star shape as a mask and animate the movement of a colored view behind it, as I suggest in this answer (where what is being filled is an apple, not a star, but it is the same technique):
https://stackoverflow.com/a/29553645/341994
Related
I need to move an image down through canvas so that its central point would be where is now its top edge. It makes some 50 points, but if I decrease y by 50, it moves to different part of the screen on devices with different screen size. I guess, it's because my main canvas is set to scale with the screen size. So I suppose I need to manually divide the number 50 by my screen height and then code to multiply by Screen.height? Isn't there a more convenient way to move UI objects?
Allow me a second question: Do you think it is even wise to make a game purely on canvas? My game is simple 2D, only slightly animated and contains many layout elements, so I decided to go for it, but I have hard time to grasp the UI position rules.
you may have the problem of the anchoring.
Unity UI totally depends on the Anchoring, if you have got right anchoring there is no issue.
For example. if you anchored something at the Center than changing left and right value moves them according to the center anchor.
for clear visualization, you can paste a screenshot of the behavior.
I am building an experimental reading app where the text passage is presented as a single line of text on the screen. The user will tilt back and forth to move the text strip backwards or forwards. What I have tried so far is:
Placed a UILabel inside a UIScrollView and manually calculating the ScrollView’s new offset depending on the current tilt. The text scrolls in an uncomfortable, jerky motion in this implementation most likely because the current acceleration equation is just a linear function. Also, I’d rather not reinvent the wheel since Sprite Kit already has tilt physics perfected, but it is just not readily applicable on text objects.
Wanting to use Sprite Kit’s buttery smooth tilt, I placed my text in an SKLabelNode and had its X coordinates match a SKSpriteNode that I gave tilt physics. This worked very well until the moment I added a paragraph’s worth of text inside the SKLabelNode. Then it turns into a black rectangle...
Stack Overflow discussions I have found concluded that SKLabelNode is not meant to be used in the way I desire and have suggested multiline implementations, or string to bitmap image conversion. Multiline is not an option for the way I want my reading app to work.
I found the code in
How do I add text to an image in iOS Swift to implement string to bitmap image conversion, then making that image an SKSpriteNode. The moment the image’s width exceeds 2000 (only enough space for a short sentence in 50 pt font), it becomes a black rectangle. I imagine up the text into smaller chunks to fit inside this 2000 limit will really complicate the code and make user statistics like words per minute much harder to calculate.
At the top is what I want the text to look like (user tilts left/right to read next/previous), and the black strip on the bottom is the black rectangle that appears if the width of the text is way too long :(
Does anyone have any suggestions for what else I could try? Once again, my requirements are:
The string must be presented as a long, single line on the screen
The user tilts the device to read forward/backward
The acceleration is smooth so it’s easy on the eyes :)
Perhaps you can try loading one sentence at a time into one SKLabelNode. You will also have a second SKLabelNode to act as the on-deck cache. When one SKLabelNode moves off the screen, you can position it at the end of the of the SKLabelNode currently on screen. That's how a table view in UIKit works. The only difference here is that your "table cells" are scrolling horizontally, and you'll have to perform the work to reset them after they move off the screen.
I was thinking of make a slider/joystick but not in a circle but in a line. So I made the image drag able only over the X axis and when it gets to the point where the slider stops i did this :
if(slider.center.x <= 60) {
slider.center = CGPointMake(60, slider.center.y);
}
so it wouldn't get bigger than 60 but i was thinking isn't there a better way to do this? like make a box and setting up something to not drag it outside that box?
Thanks!
I think this method is very good. As far as I know there is no wan to stop dragging in other ways than this.
However there is a control called UISlider. This control does the functionality you would like to have.
You could also use touchesBegan, touchesMoved, and touchesEnded, then add an image behind and detect when touch is less than half image's width (Left) or when it's greater than half (Right)
I am working on a small game, in which the user can drag rows and columns of images to solve a puzzle.
The puzzle does not use the whole screen, the "puzzle area" is in a rectangle area from 0,160 to 320,480.
Now, if the user drags a column of the images up, the top image in that column would be displayed "out of" that puzzle area. How could I only have that portion of the image shown, that remains within the puzzle area. Like not showing the whole 50x50 Pixel of the image, but only the lower 40x50 Pixel etc.?
You just need to set the frames on your views properly. If your puzzle views frame ends at the (0,160) point on top, any subviews you've added to it; such as the puzzle pieces will be hidden when they move out of the frame.
Hopefully I'm not oversimplifying the problem, but one of the easier ways I can think of working this scenario is by maintaining a proper view structure while moving the puzzle pieces.
i.e. as long as the view on the top half of the screen is higher up on the view hierarchy than the puzzle pieces (you could ensure this by properly maintaining the subviews), the puzzle pieces will be hidden under the top view if they move beneath it.
Is this what you need?
Cheers.
I am just tryin to give u some ideas.. Hope u can implement with that...
First use touchesBegan and touchesMoved methods to detect how much pixels the image has been dragged. Simultaneously u can also move the frame of the image to a new coordinate , hiding a portion of the image....tat is out of puzzle area.....
Hope this helps....
myImageView.frame=CGRectMake(0,0,50,50);
Let the above one be the actual frame. Now u have received the amt of pixels thru which the user has moved the image from touches method. Let it be some y1. To hide a part of the imageview reframe the imageview like this ,
myImageView.frame=CGRectMake(0,-y1,50,50);
negative y1 since u want to move out of the screen..
Hope this helps.
I am adding some functionality to an iPhone app, and could use some help in picking the fastest / most efficient / best practice approach for solving this problem:
At the upper-half of my screen, I have speech bubbles (think comic book) that are UIImageViews translating across the screen (dynamic x & y position). It is a UIImageView because there is an image as the background of the speech bubble.
Each speech bubble has a matching image moving around the bottom of the screen (elsewhere in the layer tree)
I would like to draw a tail (that triangle bit from a speech bubble) so the point of the triangle is tracking the lower image, with the base of the triangle being attached to the bottom of the upper UIImageView. (technically the base doesn't have to be butted against, it can overlap as long as I can match the color of my background image to the triangle).
I have already done all the tracking & drawn a line with CGContextStrokePath methods, and now I am stuck on how to replace the line with a triangle.
I have looked at drawing a triangle in Quartz and filling it. My concern is the speech bubbles are repositioned every 1/10th of a second, and it looks like drawing just the line used for proof of concept had a pretty severe performance / visual smoothness impact.
One idea I have is to do the trigonometry myself, and stretch & rotate an image of a triangle to connect each of these speech bubbles with the lower spot. Something is telling me there is a more efficient / more elegant solution, but I am not able to see it looking through the documentation. Any help on how you have or would approach this issue is appreciated. Thanks.
If the speech bubbles are fixed in size, just use a static UIImage. Set the image view's layer.position property at the point of the triangle. Then you can use view animation to move the bubbles around.
If you need the speech bubbles to be different sizes, I'd create a resizeable image using resizableImageWithCapInsets. Then I'd do the same as above to position it.
If there was something special about the speech bubble that I could't achieve with either a static image or a resizable image, I'd probably create a custom CA Layer or layers to get the effect I wanted (Like a gradient layer with a shape layer as it's mask layer)