1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Answers
    1
    Vote Rating
    0
    yablokoff is on a distinguished road

      0  

    Default Answered: How to make sprite's translation persistent?

    Answered: How to make sprite's translation persistent?


    When I drag sprites with this handler
    Code:
    'drag': function(e){
            object.setAttributes({
                translationX: e.deltaX,
                translationY: e.deltaY
            });
        }
    everything is ok, but I can't make that position changes persistent. So when I try to drag already dragged element, it starts with the same position, like it was never dragged.
    How to apply translation changes to sprites?

    Thanks in advance!

  2. Thank you for response,

    unfortunately setAttributes doesn't affect cx and cy of sprite what (I suppose) makes dragging incorrect.

    So I ended up with this solution: I store all translations for current sprite in special Object (called spriteTranslationSession in snippet). Then on each 'drag' event I sum deltas of dragging with stored translation and on each 'dragend' event I replace values of sprite's translation - that makes dragging seamless.

    Code:
    'drag': function(e){
       var surface = cmp.getSurface(),
             currentTranslation = this.spriteTranslationSession[this.active.getId()];
       this.active.setAttributes({
             translationX: e.deltaX + currentTranslation.x,
             translationY: e.deltaY + currentTranslation.y
       });
       surface.renderFrame();
    }
    Maybe that's redundant work but I couldn't find better solution.

    Thank you guys for great work!

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,047
    Answers
    3494
    Vote Rating
    850
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Have you tried this (from docs):

    Code:
    sprite.setAttributes({
      translate: {
       x: 10,
       y: 10
      }
    }, true);
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Answers
    1
    Vote Rating
    0
    yablokoff is on a distinguished road

      0  

    Default


    Thank you for response,

    unfortunately setAttributes doesn't affect cx and cy of sprite what (I suppose) makes dragging incorrect.

    So I ended up with this solution: I store all translations for current sprite in special Object (called spriteTranslationSession in snippet). Then on each 'drag' event I sum deltas of dragging with stored translation and on each 'dragend' event I replace values of sprite's translation - that makes dragging seamless.

    Code:
    'drag': function(e){
       var surface = cmp.getSurface(),
             currentTranslation = this.spriteTranslationSession[this.active.getId()];
       this.active.setAttributes({
             translationX: e.deltaX + currentTranslation.x,
             translationY: e.deltaY + currentTranslation.y
       });
       surface.renderFrame();
    }
    Maybe that's redundant work but I couldn't find better solution.

    Thank you guys for great work!

Thread Participants: 1

Tags for this Thread