-
23 Dec 2012 12:21 PM #1
Answered: How to make sprite's translation persistent?
Answered: How to make sprite's translation persistent?
When I drag sprites with this handler
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.Code:'drag': function(e){ object.setAttributes({ translationX: e.deltaX, translationY: e.deltaY }); }
How to apply translation changes to sprites?
Thanks in advance!
-
Best Answer Posted by yablokoff
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.
Maybe that's redundant work but I couldn't find better solution.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(); }
Thank you guys for great work!
-
26 Dec 2012 6:53 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,642
- Vote Rating
- 434
- Answers
- 3107
Have you tried this (from docs):
Code:sprite.setAttributes({ translate: { x: 10, y: 10 } }, true);Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Jan 2013 2:05 PM #3
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.
Maybe that's redundant work but I couldn't find better solution.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(); }
Thank you guys for great work!


Reply With Quote