Jump to content

Strange Issue With Hit Areas


ElliotBradly
 Share

Recommended Posts

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 loop
self.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. 
 
 
 
 
 
 
 
 
Link to comment
Share on other sites

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

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