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

moveTo - move to origin vs position ?


espace
 Share

Recommended Posts

hi,

when i move my "rect" after creating, he stay at is current position.

in fact he moves according his local position defined in CUBE.geom(200,400,80,30,blue)

how do you do to move it without be affected with this origin position ?

 

var container = new PIXI.Container();

var renderer = PIXI.autoDetectRenderer(320, 480,{backgroundColor : 0x1099bb});

document.body.appendChild(renderer.view);

requestAnimationFrame( animate );

var blue= 0x00c3ff
var red = 0xFF0040

var CUBE={}

CUBE.geom = function(posx,posy,w,h,color) {
	PIXI.Graphics.call(this,posx,posy,w,h,color);
	this.beginFill(color);
	this.drawRect(posx,posy,w,h)
}


CUBE.geom.prototype = Object.create(PIXI.Graphics.prototype);
CUBE.geom.prototype.constructor = CUBE.geom;

var square=new CUBE.geom(10,10,10,10,red)

var rect=new CUBE.geom(200,400,80,30,blue)

rect.moveTo(0,0)

	container.addChild(square,rect);


	function animate() {

		requestAnimationFrame( animate );
		renderer.render(container);
	}

 

Link to comment
Share on other sites

That'+s not how graphics object works. Graphics object defines a set of points and primitives inside it, you can clear it and fill it with new primitives. At the same time, any PIXI object can have its own position that will affect its coords and coords of all his children. moveTo() is method for drawing, I dont know why do you want to use it for moving the object.

It will be better if you just draw graphics relative to their local coordinates, and then change their position:

var square=new CUBE.geom(0,0,10,10,red)
var rect=new CUBE.geom(0,0,80,30,blue)

rect.position.set(200, 400);
square.position.set(10, 10);

//later

rect.position.set(0,0);

 

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...