AS2 How to get a movie clip to move forward 20 frames - actionscript-2

I have a movieclip that i want to move forward 20 frames when it touches another movieclip. I dont want it to go to a specific frame number (ex. gotoAndStop(20);) What ever frame the clip happens to be on, I want it to move forward 20 frames.

Add 20 frames to MC's _currentframe , like this:
MC.gotoAndPlay( MC._currentframe+20 );

Related

ngx-charts-bar-vertical-2d minimum bar width

I would like to set the width of the bars to be a minimum of 12px. I would actually prefer to have a fixed width on the bars period.
As an example, when I am displaying 10 days of data, the graph looks fine, but for 30 days, it does not look good at all. Any thoughts on making this look better?
I added a horizontal scroll, but the width of the bars is automatically calculated based on the number of items in the graph, irrespective of the graph width. Is there any way to alter this behavior?
Screen capture: https://share.getcloudapp.com/yAubDN8X
Try adding [barPadding]="1" to ngx-charts-bar-vertical-2d element
<ngx-charts-bar-vertical-2d [barPadding]="1" ...>...</ngx-charts-bar-vertical-2d>
Try adding [groupPadding]="1" to ngx-charts-bar-vertical-2d element
<ngx-charts-bar-vertical-2d [groupPadding]="1" ...>...</ngx-charts-bar-vertical-2d>
as long as you minimize the padding between groups, the barWidth with grow automatically !

CorePlot - dynamic x-axis data using two arrays

This is more of an open discussion topic than anything else. Currently I'm storing 50 Float32 values in my NSMutableArray *voltageArray before I refresh my CPTPlot *plot. Every time I obtain 50 values, I remove the previous 50 from the voltageArray and repeat the process....always displaying the 50 values in "real time" on my plot.
However, the data I'm receiving (which is voltage coming from a Cypress BLE module equipped with a pressure transducer) is so quick that any variation (0.4 V to 4.0 V; no pressure to lots of pressure) cannot be seen on my graph. It just shows up as a straight line, varying up and down without showing increased or decreased slopes.
To show overall change, I wanted to take those 50 values, store them in the first index of another NSMutableArray *stampArray and use the index of stampArray to display information. Meanwhile, the numberOfRecordsForPlot: method would look like this:
- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plotnumberOfRecords {
return (DATA_PER_STAMP * _stampCount);
}
This would initially be 50, then after 50 pieces of data are captured from the BLE module, _stampCount would increase by one, and the number of records for plot would increase by 50 (till about 2500-10000 range, then I'd refresh the whole the thing and restart the process.)
Is this the right approach? How would I be able to make the first 50 points stay on the graph, while building the next 50, etc.? Imagine an y = x^2 graph, and what the graph looks like when applying integration (the whole breaking the area under the curve into rectangles).
Look at the "Real Time Plot" demo in the Plot Gallery example app included with Core Plot. It starts off with an empty plot, adding a new point each cycle until reaching the maximum number of points. After that, one old point is removed for each new one added so the total number stays constant. The demo uses a timer to pass random data to the plot, but your app can of course collect data from anywhere. Be sure to always interact with the graph from the main thread.
I doubt you'll be able to display 10,000 data points on one plot (does your display have enough pixels to resolve that many points?). If not, you'll get much better drawing performance if you filter and/or smooth the data to remove some of the points before sending them to the plot.

Unity Change Ball Direction after hitting paddle in a Pong game (like in dx-ball)

I'm struggling with how to get the ball to change the bounce based on where it hits on the paddle. Normally in a pong game, the angle changes, depending on how far from center the ball bounces, and which direction of the center it bounces.
I managed to do something like that:
//rb = rigidbody, velOnPaddleHit = predefined float
float dist = transform.position.x - paddle.position.x;
dist = transform.position.x > paddle.position.x ? dist : -dist;
dist /= paddle.localScale.x/2;
dist *= velOnPaddleHit;
rb.addForce(dist, 0,0);
But it's just not working / it's weird.
Can anyone help me?
Edit: Here's the video showing this kind of behaviour. When the ball hits the left side of the paddle, it goes left, the velocity doesn't matter
https://www.youtube.com/watch?v=fHX_2DLDp1w
You do't change it based on where it hit the paddle. To change the direction of the ball, all you have to do is to flip the numbers in the opposite direction. So multiplying x and y axis rigidBody value by -1 and applying it to the ball should do just that.
if ball collides with the paddle,multiply the velocity of the ball's rigidBody in all axis by -1, except for the z axis or the x-axis(Depends on how you setup your scene. It could ether z or x axis but the y-axis MUST be multiplied by -1 in other to go in the other direction.
You may have a speedVariable that increases the speed of the ball each time it hits the paddle.
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.name == "ball")
{
Vector3 tempVect = new Vector3(collision.rigidbody.velocity.x * -1, collision.rigidbody.velocity.y * -1, collision.rigidbody.velocity.z);
collision.rigidbody.velocity = tempVect;
}
}
To detect where the ball hit, the easiest way I know about is to use tiny box colliders.
Create at-least 24 box colliders. Name them from detector1 to detector24
(detector1, detector2,detector3,detector4,detector5.....)
Mark isTrigger of 24 of the box colliders true so that they wont collide with the ball.
Create a layer called "detectorLayer" and make sure that those 24 box colliders are in the "detectorLayer" layer.
Create another layer called "ballLayer" and make sure that the ball's layer is set to "ballLayer".
Attach a collider to your paddle called. Change your paddle's GameObject name to "Paddle". Create a new layer called "PaddleLayer" and make sure that "Paddle" GameObject is in the layer called "PaddleLayer".
Position those 24 colliders from left to right in order close to the paddle but make sure they are not touching the paddle or the collider of the Paddle. The image below should help you understand what I am taking about.
Writing the code should be piece a piece of cake.
bool firstColision = false;
Check If ball collides with Paddle with OnCollisionEnter.
firstColision = true;
Immediately check which of the 24-colliders the ball is touching with the OnTriggerEnter function.
Inside the OnTriggerEnter function, make sure firstColision is true before checking which of the 24 box colliders is touching the ball.
The first box collider called "detector1" is positioned on left-most side while the last box collider called "detector24" is positioned to the right-most side of the padder. You can use if if statement or the switch statement todetect which box collider the ball triggered. 24/2 = 12 so box collider named "detector24" should be positioned in the middle and should be considered the middle of the paddle.
(ACTION) After detecting which box number the ball hit from with OnTriggerEnter, now you can do whatever you want. For example, make the ball go left or right. You may have constant values that dictates how far to move the ball for each box collider detected. That's up to you. You make your own rules from here now.
Set firstColision to false to reset it.
NOTE: It doesn't have to be 24 box colliders. It can be 15 but the more you have have, the better.
If everything works as expected, you can do the final part which is to go to Edit->Project Settings->Physics and make sure that the following is true:
A. detectorLayer cannot collide with detectorLayer.
B. PaddleLayer cannot collide with detectorLayer.
This will improve performance on mobile devices.

Looping a specific segment of a movie using AVPlayer - always seeks back to beginning

I have a video that is about 12 seconds long. Seconds 5-10 are loopable.
I want to play the video from the start the first time, then continue to loop over seconds 5-10 afterwards indefinitely.
However when I try, the video just jumps back to the beginning again.
Am I doing something wrong here? The video is H.264 mp4 format.
Here's a snippet of code I use: (the update function gets called every frame)
-(void) update:(double)timeDelta
{
if ( !m_player ) {
return;
}
CMTime time = m_player.m_player.currentTime;
if ( CMTimeGetSeconds(time) > 10.0f ) {
[m_player seekToTime:CMTimeMakeWithSeconds(5.0f, time.timescale)];
}
}
Any help would be much appreciated.
Thanks,
Rich
Most players will only seek to I pictures (Intra pictures). It may be that your clip only has a I picture in the begining and another one after 5 seconds. Check that. If you can re-encode, then re-encode with I pictures inserted every 1 second to allow you to do this.
It's probably seeking to a keyframe, if the keyframe interval on that particular video is greater than 5 seconds.
Try either adjusting the way the video is encoded such that you are able to get a keyframe at the 5 second mark or use
[m_player seekToTime:CMTimeMakeWithSeconds(5.0f, time.timescale) toleranceBefore: kCMTimeZero toleranceAfter: kCMTimeZero];
Note that if you do this, the decoder will have to decode those 5 seconds of video before resuming playback at the point you want, so you may end up with a brief delay in your loop.

Touch a sprite without boundingBox

So i'm trying to move multiple sprites on the screen at the same time. The problem is that if the 2 sprites are close to each other the position becomes the same (so the bounding box is the same) and i can't seem to pull them apart.
I'm using the "standard" CGRectContainsPoint(sprite1.boundingBox,location).
What i need is to get the sprite on top regardless of boundingBox. Any ideas?
One way would be to start assigning explicit z values to sprites you add, using CCNode's -(void) addChild: (CCNode*)node z:(NSInteger)z method.
Then, when you get multiple sprites back from your bounding test, only move the one with largest z value.
hah..i fixed in the easiest way possible :\
if (CGRectContainsPoint (sprite1.boundingBox,location)){
sprite1.position=location;
}else if (CGRectContainsPoint (sprite2.boundingBox,location)){
sprite2.position=location;
}
the way this behaves is that if the bounding boxes are the same..it only takes one..not the 2nd one