I am having difficulties implementing the marquee (scrolling) text view in SwiftUI. The problem is that the text needs to stay in the original (0) position for 2 seconds and the starts moving to the left, show up on the right and continue scrolling until the 0 position and wait for 2 seconds again.
You can work with what's in this video to get something working, but honestly it's difficult to make it work with varying screen sizes if your view is in any way responsive. But if you are using the foundation in that video for the animations and combining that with a geometry reader to get your zero position and rightmost entry point position, you could get the scroll positioning correct.
As for starting and stopping, I would suggest you use a Timer to toggle a boolean #State variable called scrollText to start/stop the animation 2 seconds after its duration. You would start by first toggling the animation in .onAppear, like this:
Text("Hello World")
.offset(x: scrollText ? zeroPoint : screenEntryPoint)
.animation(Animation.linear(duration: 8).repeatForever(autoreverses: false))
.onAppear {
self.scrollText.toggle()
}
If you then set a timer for 10 seconds to toggle scrollText, you would be able to get the animation to run for 8s, pause 2 seconds, and then run again.
Please note that to make marquee text work, you also need to REPEAT the text twice, so that the text will animate in from the right while it's also leaving from the left. Good luck!
Related
I have a character sheet for the player that triggers when they are idle for a while. The sheet has them going from standing to laying down in 6 frames, sleeping for 3 frames and then standing back up in 7 frames.
I'm looking to pause the animation when it reaches the 9th frame without using timers (as the character sheet may change in the future). Is there a function that will let me query which animation frame is currently being displayed?
Alternatively, is there a way to know if a character sheet has reached the last frame and is about to return to the first frame. I need to know when this animation has finished a cycle so I can smoothly transition back into the walking animation.
I'm extending Modern Algebra's ExtraMovementFrames plugin, so the solution ended up being to capture the output of this:
var patternIndex = (this._pattern % this.emfCharacterState().pattern.length);
which uses the ._pattern property of the player, modulo the length of the animation.
I then used this.setStepAnime(false); to pause the walking animation of the character once it reached the desired frame.
Also asked this on the rpg maker mv forums: https://forums.rpgmakerweb.com/index.php?threads/checking-which-frame-of-a-character-sheet-is-currently-active.115662/
I have a sprite animation of 30 frames, 6 of these frames are keyframes and the rest are transitions from keyframe to keyframe.
I am trying to figure out how to do the following:
When button is pressed the sprite starts animating. Animation will run at least once and then it will stop the animation on a randomly chosen keyframe.
When button is pressed again, animation will start from the last chosen keyframe and will run 1 complete cycle and then stops again on a randomly chosen keyframe.
I've found a similar question here but that was asked in 2014. Did Swift and Spritekit change enough in 3 years to make it possible?
Edit:
#Alessandro Ornano
I've tried this:
var roll1Textures = ["Roll1Motion0", "Roll1Motion1", "Roll1Motion2", "Roll1Motion3", "Roll1Motion4", "Roll1Motion5", "Roll1Motion6", "Roll1Motion7", "Roll1Motion8", "Roll1Motion9", "Roll1Motion10", "Roll1Motion11", "Roll1Motion12", "Roll1Motion13", "Roll1Motion14", "Roll1Motion15", "Roll1Motion16", "Roll1Motion17", "Roll1Motion18", "Roll1Motion19", "Roll1Motion20", "Roll1Motion21", "Roll1Motion22", "Roll1Motion23", "Roll1Motion24", "Roll1Motion25", "Roll1Motion26", "Roll1Motion27", "Roll1Motion28", "Roll1Motion29"]
let roll1Animation = SKAction.animate(with: Array(roll1Textures[0...5]), timePerFrame: 0.06, resize:false, restore:false)
But I get an error message: Cannot use instance member 'roll1Textures' within property initialiser; property initialisers run before 'self' is available.
How did I implement your code in a wrong way?
I don't know if it could be useful to your game but now in Swift you can also do in one line:
let animation = SKAction.animate(with: Array(textures[0...5]), timePerFrame: 0.06, resize:false, restore:false)
In other words you can create an array slice composed by your specific range then re-create the array of textures with Array
Trying to very simply scroll a famous Scrollview to a pixel position with a transition. It looks like Scrollview's setPosition function will set the scroll position in pixels (right?). But how do I add a transition to this.
My first thought was to use a Transitionable to move from the scrollview's getPosition to the end position, but this led to another question: How do I watch a transitionable?
Thanks!
Right now the famous Scrollview does not support setting the position with any kind of transition. There are a number of things you can do to simulate the transition, such as dividing the total difference in position by the length of the transition and then adding that value to the position every render frame. This would give the illusion of a transition.
I'm currently trying to make a grid that animates from collapsed -> visible to notify the user that the save has been completed. In Blend 4 I opened the project and created a usercontrol for the SaveNotifier so I can use it in other areas of this project and others. I created the default to be collapsed and also created another state called "Complete" which has visibility set to Visible and has a timetrigger of 3 seconds which sends it back to the default state. The transitions are set to transition over 1 second and use fluidlayout to show the animation between the states, but it does not show the animation between states. Instead it just shows it as if there was no fluidlayout or transition time.
If someone would be so kind as to let me know if there is a problem with trying to do this or even show me how to do this it would be gre
Not sure why, but when I put the grid inside of a new grid it started working. Seems as if you need to have a grid to be the full size for the animation to display.
I have a UITabBarController inside a UIPopoverController, which I am displaying solely from one UIBarButtonItem. When shown I want the popover to take up the maximum vertical height allowed. It works fine if I tap to display it, then dismiss, and then rotate. However if I have the popover displayed in landscape, and then rotate to portrait, it no longer will fill the entire vertical distance. I have the tab bar controller's content size property set to 320 by 1000, and I have even tried resetting this every time the device rotates. Worse yet, when the user activates the search bar the popover shrinks up extremely small, and stays that way until the app is restarted.
http://cl.ly/3JdC to http://cl.ly/3JdC
Also http://cl.ly/3JVF
How can I stop this, and have the popover always fill up the max vertical size?
I was just having the same problem and found out that it only happens when I present the UIPopoverController using the method:
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
but it works fine when I use:
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
Unfortunately UIBarButtonItem does not have a frame Rect you can use with this last method so my fix was to use the UIToolbar's frame and modify frame.origin.x and frame.size.width accordingly to make the popover appear on the right place next to the UIBarButtonItem.
Hopefully Apple will fix this in next releases of iOS.
Regards