In wxWidgets, is it possible to have on a wxPanel, an object that contains a mouse click event which moves the objects to another location when activated? The movement should be seen as an animation, e.g. Sliding from its initial location to the next location (Using wxTimer?). Is this by any means, possible?
Basically you need to change the position of whatever you are displaying smoothly so a timer at 25 Hz and then update the position a proportion of the movement each time, e.g. if you need to move from 0,0 to 100,200 smoothly in 4 seconds then updating your position by +1,+2 each timer event should do nicely. You may find that you need to invalidate a display area that includes the position before the move and after it to force a redraw but give it a try without first.
Related
Subject says it all. I'm actually using the label as a pseudo progress bar, so it has a solid blue background color, no text, and I'm increasing its width on each timer tick. This works great except for one oddball case:
If I leave the window up all day, it's fine.
If I minimize for less than a minute and restore, it's fine.
It's only when I minimize for over a minute (long enough that a tick actually fires), then restore the window, the label doesn't repaint. That is, other labels, which aren't dynamically updated during the tick show up when I restore the window, but the special label that IS dynamically updated is not repainted (the pixels I would expect to be blue are the window's background color, a very light gray). Yes, if the restored window sits there until the next tick, the label repaints blue in the expected way. The window isn't locked up - it responds to input. I'm using a Windows.Forms.Timer dragged onto the form, not a System.Timers.Timer in code.
So, user error or OS/.NET framework bug?
Edit 1: Per answer 1 below, the problem is triggered by attempting to read the width of another label. Why would the window's minimized state affect reading the width of a label?
I've isolated it down to this one line of code, which is in the sub that my tick event calls:
fakebar.Width = Int((spanSoFar / spanOverall) * (fakeborder.Width - 2))
Inexplicably, omitting the read of the fakeborder object (a label that does NOT get dynamically updated) fixes the problem:
fakebar.Width = Int((spanSoFar / spanOverall) * (366))
This doesn't seem like user error, but there could be something going on I'm not aware of.
I'm using performBatchUpdates: to insert a new section to my collection view. This comes with the default fade in animation that I'd like to keep. The item I'm inserting is always the last item, so I'd like to offset my collection view to the bottom to make it visible.
Right now I'm able to achieve this by using scrollRectToVisible: in the completion callback of the batch update method. However, by the time it scrolls, the fade in animation already happened out of frame.
I'd like for both to happen simultaneously. Is this possible?
One approach I've tried is pre-calculating the new size manually ahead of the updates and scrolling first, but then the cells get reused right on screen, appearing and disappearing, which is not ideal.
Any ideas?
I have a UIImageView that moves around the screen, and I am trying to trigger a method when it is within a certain distance of another UIImageView, also moving. There is not necessarily any specific time I want to check, I want to know anytime it is within that distance. Help!
EDIT: I have multiple objects(the enemies) moving down the screen while the player is at the bottom of the screen. When the user taps the screen, it "shoots"(a new projectile object is created and the animation to move it up the screen is started). I am trying to detect when the "projectiles" hit the "enemies" and triggering an event(i.e. killing the enemy). I have no idea where to put the code to do this, or even what to do. Do I want to use the Notification System, or do I want to calculate if the projectile will hit the enemy as soon as it is fired?
You probably want to use Key-Value Observing. Here's an example.
How do I make the UIScroll view show complete views, not partial views?
(Note) I don't want it jumping to a complete view. It needs to move naturally or at least not immediate... needs to be smooth.
thanks
If your views are all of a constant size and you just want left/right or up/down scrolling, set pagingEnabled on the scroll view to YES. Supposing you wanted your scroll view to be 320x480 but to show the sides of the next and previous pages (so, e.g., each thing inside the view was 280 points wide), you'd size the scroll view to be 280x480 but set masksToBounds to NO.
If you have a more complicated scheme, install a scroll view delegate and act on scrollViewDidScroll:, paying attention to contentOffset. Probably you want to implement logic like:
add an observer on tracking; when it transitions to NO from 'YES' enable your logic inside scrollViewDidScroll: In there:
if a forced scroll is pending, cancel it
calculate where you'd force the scrolling to from the current position
schedule a scroll to there (which you'll effect via setContentOffset:animated:) for half a second from now
You can use a non-repeating NSTimer for the scheduling aspect. The logic you've essentially implemented is that if the user stops adjusting the view, wait for the natural inertia to end (which you'll detect by the 0.5 second gap since last movement), then transition smoothly to the nearest aligned position.
Check out Apple's documentation here first:
https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/Introduction/Introduction.html
Then the ScrollViewSuite sample:
https://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008904
I think you are referring to Paging techniques.
I am creating a small applicaiton for simulating dice roll. To simulate bounces I change the position of the picture randomly. Now to simulate more than one bounce, I used a for loop to continuously change the position of the picture box. But it is not happening as I planned, the form only displays the position of the last loop. I even tried using System.Threading.Thread.Sleep(1000) hoping to show the bounces, but even they show the last loop only.
For bounceCount As Integer = 1 To bounces
bounce(pb_dice1)
bounce(pb_dice2)
System.Threading.Thread.Sleep(3000) 'I need to pause here and show the recent change in position then continue after 3 seconds
Next
the bounce method changes the position of the PictureBox.
How can I pause my for loop, display the newly positioned dices, and then continue after 3 seconds?
Controls don't refresh their graphics until event handlers finish executing. Otherwise, if several changes were made to one or more controls, they would refresh repeatedly when all you really want is the end result.
To force a control to refresh it's graphics, you need to insert the following line before sleeping:
PictureBox1.Refresh()
You may have to change PictureBox1 to the name of another control, of course. Also, it may be worth refreshing the parent control (ie. the control that contains the dice.)
I guess you should use Application.DoEvents() before calling Sleep().