ElliotBradly Posted October 3, 2014 Share Posted October 3, 2014 I have a code in my main render loop to dynamically position a row of buttons.However it appears that the hit area of the buttons get thrown off by many pixels because of it.I wondered if any of the PIXI experts knew what I was doing incorrectly to cause this error. //This is the function which creates the assets I wish to use self.create = function(){ self.display1 = new PIXI.DisplayObjectContainer(); self.stage.addChild( self.display1 ); var texture = PIXI.Texture.fromImage("soul/icon/background/rough.png"); self.button = new PIXI.Sprite(texture); self.button.setInteractive(true); self.button.position.x = 100; self.display1.position.x = 100; var button = self.button; button.mousedown = button.touchstart = function(data){ trace("mousedown"); } button.mouseup = button.touchend = function(data){ trace("mouseup"); } self.display1.addChild( self.button ); } // this is the main loopself.render = function(){ if ( self.display1 == null ) return; var newX = 1000 - self.display1.width * .5; self.display1.position.x = newX; } afterwards the hit area are off on the button by quite abit.Now if i replace self.display1.width with an integer all is working fine. I am using Pixi.js v1.6.1. I have spent half the afternoon wondering how to get this to work correctly.Any advice or solutions you have with be VERY appreciated. Thank you so much for reading. Quote Link to comment Share on other sites More sharing options...
hubert Posted October 4, 2014 Share Posted October 4, 2014 HI! this is quite strange. I am wondering is it possible that while you are adding elements to the displayObjectContainer it changes it's width? Object Containers were meant to be wrappers for pixie sprites and i think that their bounds are dynamic based on the positions of the children. Could you console.log(self.display1.width) while in the loop? Maybe that is the issue? Second thing. Are the hit areas going in all different directions or are they always "travelling" left or right? https://play.google.com/store/apps/details?id=pl.com.wojciak.kontakt.new_words http://www.sevenative.com Quote Link to comment Share on other sites More sharing options...
BasomtiKombucha Posted October 5, 2014 Share Posted October 5, 2014 Also try to console.log.(self.display1.hitArea) and see if it outputs something unexpected. hubert 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.