Jump to content

Create Sprite with DisplayObject of circle


Matthias Elephant
 Share

Recommended Posts

Hmmm, but i need a sprite that returns a Phaser.Circle if i call sprite.getBounds() (i always get the Rectangle).

Then i can check, if two circles are overlaped to another. I can't use a physics body because my sprite is a children of another sprite and this didn't work.

Now i'm looking for a workaround without physics. But this just works if i have a sprite with displayobject 'circle'.

 

Thanks

 

Link to comment
Share on other sites

Ok then i misunderstand the documentation.

Alternative: It is possible to make the Rectangle (that i get at "sprite.getBounds()" ) smaller?

Sprite.scale is not that what i'm looking for. The visual component that the user see, should be the same size as before. Only the "physical" rectangle should be smaller for a better "overlap" of two circles.

Link to comment
Share on other sites

Thanks for all you answers.

I already use the p2 physics engine (need polygons some some sprites).

In following example i have a two sprites. A parent and a children. The children is a circle, but the positioning didnt work. 

Just copy my following example code to: http://phaser.io/examples/v2/p2-physics/basic-movement#gv
 

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

function preload() {
    game.load.image('atari', 'assets/sprites/atari130xe.png');
}

var sprite;
var children;

function create() {
	game.physics.startSystem(Phaser.Physics.P2JS);

	children = game.add.sprite(100, 100, 'atari');
	children.scale.set(0.5);
	game.physics.p2.enable(children, true);
	children.body.setZeroDamping();
	children.body.moveRight(10);
	children.body.setCircle(30);

    sprite = game.add.sprite(200, 200, 'atari');
	game.physics.p2.enable(sprite, true);
	
	sprite.body.setZeroDamping();
	sprite.body.moveRight(10);
	//sprite.body.rotateLeft(10);
	
	sprite.addChild(children);
}

function update() {
}


Thanks for any help! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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