espace Posted July 6, 2016 Share Posted July 6, 2016 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); } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted July 6, 2016 Share Posted July 6, 2016 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); Quote Link to comment Share on other sites More sharing options...
espace Posted July 6, 2016 Author Share Posted July 6, 2016 thanks for your response, i understand better now. have a nice day ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.