Jump to content

Cannot drag sprite


Babsobar
 Share

Recommended Posts

Hello,

Just starting with Phaser here and  I've got a really big noob question here.

i'm working on my game and I can't seem to get my sprite to move even though i'm using this code: I tried looking through the documentation and got to this example bound sprites, 

even though the code on the example works, for some reason it's no go on my local server, even though everything is rendered as it should.

 

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'container', { preload: preload, create: create, update: update });
// var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {
		game.load.atlasJSONHash('main','assets/main.png','assets/main.json');
}


function create(){
        game.input.enabled = true,


	var airport = game.add.sprite(200,200,'main','airport.png');
		airport.inputEnabled = true;

		airport.input.enableDrag(true);
	
	


	function update(){
}

I feel dumb for not getting this to work.

Link to comment
Share on other sites

I'm not sure I understand your doupt, you're trying to drag your sprite?

If yes try this:

var game= new Phaser.Game(this.window.innerWidth, this.window.innerHeight, Phaser.AUTO, "pgame",{preload: preload, create: create, update: update});

function preload()
{
    this.load.image('potato','potato.jpg');
}
    
function create()
{  
    this.potato = this.add.tileSprite(0,0,50,50,'potato');
    this.potato.inputEnabled = true;
    this.potato.input.enableDrag();
}
    
function update()
{

}

 

Link to comment
Share on other sites

 I'm getting a" "this.airport" is undefined", i've adapted my code to your example , here it is:

 

function preload() {
		this.load.atlasJSONHash('main','assets/main.png','assets/main.json'); 
}



function create()
{
	this.airport = this.airport.add.sprite(200,200,'main','airport0.png');
	this.airport.inputEnabled = true,
	this.airport.input.inputDrag();
}
function update()
{
 }

Why are you using the "this" keyword, seems like that might become complicated once code becomes more complex?

Link to comment
Share on other sites

Checking back in to say that I fixed my problem, the reason it wasn't working was because another call for phaser.min.js was at the end of my code.

Calling it two times seems that it activates some functions, but doesnt do input, so I had Phaser working, but only at half-life.
 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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