espace Posted January 11, 2017 Share Posted January 11, 2017 hi and happy new year. to design my interface i use this part of snippet. it's simple and when i want to catch the position of my "this" i see the ruler in chrome dev tools or in firefox dev tools. I was wondering if it would not be possible to retrieve the coordinates of my object directly after I moved it.For example with another button that activates a function...The problem is that I do not see how to say this.x = this_x_after_drag and then keep this data so that when refreshing my page, the object is at the new coordinate.Do you have a track? class_name = function(game){ Phaser.Sprite.call(this,game,0,0,'image') this.flag_drag=true this.flag_drag && this.allow_drag(this) } class_name.prototype.allow_drag = function(obj) { obj.inputEnabled=true obj.input.enableDrag(true) } Link to comment Share on other sites More sharing options...
espace Posted January 12, 2017 Author Share Posted January 12, 2017 Nobody ? Link to comment Share on other sites More sharing options...
drhayes Posted January 12, 2017 Share Posted January 12, 2017 Sorry, I'm not clear what you're asking. You want to drag your sprite and log what its new position is? Link to comment Share on other sites More sharing options...
espace Posted January 13, 2017 Author Share Posted January 13, 2017 hi, yes i want to drag my sprite but i also want the end coordinates to be saved so that when I refresh my page the object is positioned at those last coordinates. Link to comment Share on other sites More sharing options...
drhayes Posted January 13, 2017 Share Posted January 13, 2017 A drag is one down event, a lot of move events, then an up event (usually... screen/canvas edges can make this a little complicated). Why not store the position during the move events during a drag? As far as persisting the data, it depends. Does your game have a server connected to a database? Is it okay if it's only stored in the user's browser (you can use localStorage)? Do you mind it getting stored in someone else's storage (use Firebase)? Link to comment Share on other sites More sharing options...
phreaknation Posted January 16, 2017 Share Posted January 16, 2017 I would suggest using localstorage if you are creating a front end plugin that you do not want to require a backend for. Otherwise, backend DB. I pretty much support @drhayes on this one Link to comment Share on other sites More sharing options...
espace Posted January 17, 2017 Author Share Posted January 17, 2017 thanks i will try with your both advices Link to comment Share on other sites More sharing options...
Recommended Posts