CCEaseSineIn Odd Behavior

I am trying to move an object up and down the screen using a sine ease but it looks like its doing some sort of a bounce or elastic ease. If I move from point A to point B it goes way past B and then comes back to it.

var up = new CCMoveTo (2f, new CCPoint (center.X, center.Y + 160));
var upEase = CCEaseSineIn (up);
sprite.RunAction(upEase);

Doing this same thing in cocos2d-x show a smooth animation that gradually changes speed but never goes past point B.

Is there something i need to do to get it to tween correctly?

Answers

  • RandyCooperRandyCooper USMember

    I think this might be an issue with CCEaseMath. I was able to use a custom ease with a sine in function and it worked like I was expecting.

        private void MoveDown()
        {
            var down = new CCMoveTo (0.5f, new CCPoint (center.X, center.Y));
            var ease = new CCEaseCustom (down, SineIn);
    
            sprite.RunAction (ease);
        }
    
        private float SineIn(float time)
        {
            return (float) Math.Sin(time * (Math.PI / 2) - (Math.PI / 2)) + 1;
        }
    

    I've only tested the sine functions so I don't know if any others have issues.

  • RandyCooperRandyCooper USMember
    edited August 2015

    Here is sine out.

        private float SineOut(float time)
        {
            return (float) Math.Sin(time * (Math.PI / 2));
        }
    
  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Randy

    Thanks for letting us know. Have set up an issue here. You are more than welcome to submit a PR for this if you would like.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Randy

    Never mind about the PR is re-read the code and you are using CCEaseCustom which I did not see before. Thanks

  • RandyCooperRandyCooper USMember

    I've also noticed some lag while running repeated actions on android devices(Galaxy S3). Have you heard anything about that? I'm recreating my actions and sequences every time I start over, is that a huge performance hit?

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @RandyCooper

    This easing should be fixed now. https://github.com/mono/CocosSharp/issues/286

    After looking up the tween functions it looks like the SineIn and SineOut functions have not been correct for a while. Thanks for catching that.

    private float SineIn(float time)
    {
        return -1f * (float)Math.Cos(time * (Math.PI / 2.0)) + 1f;
    }
    
    private float SineOut(float time)
    {
        return (float) Math.Sin(time * (Math.PI / 2.0));
    }
    
  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @RandyCooper

    How are you structuring the creation and where are adding them in your code. Is this a lag from the time you add them to the time they actually run?

    You should not have to recreate them if they are always the same. Cocos2d-x you would use a copy() but you can define them once and reuse them as many times as needed as long as they do not change.

  • RandyCooperRandyCooper USMember

    I have a CCActionSequence that contains an action to move up then another to move down and runs for 1 second. When the sequence is complete it will play again. Right now I am creating a new sequence every time I start a new loop. On ios and the android emulator (Xamarin Player) it runs just fine but when I put it on my Galaxy S3 the framerate will occasionally drop by half and then go back up making it look very choppy.

  • RandyCooperRandyCooper USMember
    edited August 2015

    I also have the formulas for the other easing functions if you would like those as well.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Can you just reuse the sequence ? How are you calling the sequence?

  • RandyCooperRandyCooper USMember

    I have a sequence with to easing function and a CallFunc. In the action of the CallFunc I just do a sprite.RunAction(). It works great on iOS but it's very choppy on all android devices.

Sign In or Register to comment.