Jump to content

phaser onDragStart not working


1ipt0n
 Share

Recommended Posts

Hi,

I'm trying to make simple joystick (yes i know there is  a plugin ) for my game. 

the problem is onDragStart is not working and even if I dont use this event I get error every time I'm starting dragging. everything else is working fine. Even onDragStop is ok.

 

error:

Uncaught TypeError: undefined is not a function phaser.js:31216Phaser.InputHandler.startDrag phaser.js:31216Phaser.InputHandler._touchedHandler phaser.js:30885Phaser.Pointer.start phaser.js:29001Phaser.Input.startPointer phaser.js:27272Phaser.Touch.onTouchStart phaser.js:29757_onTouchStart phaser.js:29677// the last line in phaser.js is: if (this.game.device.touch)        {            this._onTouchStart = function (event) {                return _this.onTouchStart(event);            };//the first one:       if (this.sprite.fixedToCamera)        {            if (this.dragFromCenter)            {                this.sprite.centerOn(pointer.x, pointer.y);                this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y);            }            else            {                this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y);            }        }

and there is my code:

addJoystick = function(x,y,r, show_level){    var boundries = new Phaser.Rectangle(x-(r/2),y-(r/2),r,r);    var bottom = game.add.graphics(x,y);    bottom.beginFill(0xFF3300,0.3);    bottom.lineStyle(2, 0xffd900, 1);    bottom.drawCircle(0,0, r);    bottom.fixedToCamera = true;    var stick_r = r/2.5;    var stick = game.add.graphics(x,y);    stick.base_r = r;    stick.beginFill(0xFFcc00,0.3);    stick.lineStyle(2, 0xffd900, 1);    stick.drawCircle(0,0, stick_r);    stick.base_cameraOffset = [stick.cameraOffset.x,stick.cameraOffset.y] ;    stick.inputEnabled = true;    stick.level =0;    stick.level_start=false;    if(typeof(show_level)!='undefined'){        var level_bar = game.add.graphics(x,y);        level_bar.beginFill(0xFF0000,0.8);        level_bar.lineStyle(2, 0xffcccc, 1);        level_bar.drawCircle(0,0, 1);        level_bar.max_r = r;        level_bar.fixedToCamera = true;        stick.level_bar = level_bar;        stick.update = function(){            if(this.level_start){                console.log(this.level_bar);            }        }    }    //  enableDrag parameters = (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite)    stick.input.enableDrag(true, true, false, 255, boundries );    stick.fixedToCamera = true;        stick.get_x = function(){        var offset = this.base_cameraOffset[0] - this.cameraOffset.x;        return (offset/this.base_r)*200;    };    stick.get_y = function(){        var offset = this.base_cameraOffset[1] - this.cameraOffset.y;        return (offset/this.base_r)*200;    };    stick.events.onDragStart.add(function(item){        item.level_start=true;        item.level =0;            }, this);    stick.events.onDragStop.add(function(item){        item.cameraOffset.x = item.base_cameraOffset[0];        item.cameraOffset.y = item.base_cameraOffset[1];        item.level =0;        item.level_start=false;            }, this);    return stick;};
Link to comment
Share on other sites

hi, me again, I've changed:

 

stick.input.enableDrag(true, true, false, 255, boundries );

 
to
 
stick.input.enableDrag(false, false, false, 255, boundries );
 

 

and everything works fine now.

so probably phaser have something wrong going one with draging primitives and lockCenter, bringToTop.

 

problem solved :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...