Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Collision with Sprite Animation doesn´t work properly


delueg
 Share

Recommended Posts

Hello,
 
currently i am working on my first Phaser Game and running into a collision detection Problem when i use spritreanimations.
 
For me it seems that my player ( normal sprite ) get hit by the enemy ( sprite animation ) aldready when the "big sprite" behind the animation collide with my player.

Means that the player gets hit WAY before a collision is visually recongized
 
Could this be true?
 
Here is some of my code.

 

//load the sprite -> only using atlas causing error: Uncaught TypeError: Cannot read property 'sourceSizeW' of null

this.game.load.atlasJSONHash("enemy_1", "assets/enemy_1.png","assets/enemy_1.json");

//Create the group with the enemies -> no difference between using setRectangle an immovable = true or not

this.fast_obstacle = game.add.group();		for (var i = 0; i < 10; i++)		{			//  They are evenly spaced out on the X coordinate, with a random Y coordinate			sprite = this.fast_obstacle.create(app.w, game.rnd.integerInRange(0, app.h), 'enemy_1', 'boss10000',false);			/*sprite.body.setRectangle(100, 50, 50, 25);			sprite.body.immovable = true;*/		}		//  These are the frame names for the octopus animation. We use the generateFrames function to help create the array.		var frameNames = Phaser.Animation.generateFrameNames('boss1', 0, 37, '', 4);		console.log(frameNames);		this.fast_obstacle.callAll('animations.add', 'animations', 'swim',frameNames, 20, true, false);		this.fast_obstacle.callAll('play', null, 'swim');

//check for collision -> no difference between using collide or overlap

 this.game.physics.collide(this.player, this.fast_obstacle, this.player_death, null, this);

//add to stage

// Get the first dead obstacle of our group			var fast_obstacle = this.fast_obstacle.getFirstDead();			// Set the new position of the obstacle			fast_obstacle.reset(x, y);			app.counter = 0;			fast_obstacle.body.velocity.x = app.speed * 2;			fast_obstacle.outOfBoundsKill = true;

any help would be very nice thanks :)

Link to comment
Share on other sites

i could solve my problem..

 

it was a problem with my json file, i just change the trimmed-property to false

"boss10000":{	"frame": {"x":10,"y":10,"w":200,"h":256},	"rotated": false,	"trimmed": false,	"spriteSourceSize": {"x":587,"y":26,"w":902,"h":397},	"sourceSize": {"w":902,"h":397}},
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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