Results 1 to 3 of 3

Thread: How to make sprite's translation persistent?

  1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Answers
    1
    Vote Rating
    0
      0  

    Default 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 User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,060
    Answers
    3976
    Vote Rating
    1389
      0  

    Default

    Have you tried this (from docs):

    Code:
    sprite.setAttributes({
      translate: {
       x: 10,
       y: 10
      }
    }, true);
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    5
    Answers
    1
    Vote Rating
    0
      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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •