Results 1 to 8 of 8
  1. #1
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888

    centering text strings in 3D??

    I am trying to center a text in 3d space over mouse over objects...I tried using alignment but using the list type gives no results...I assume it is not supported in GE.
    I have also tried using the len(string) * fontWidth / 2 and other trickery I can get it close, but ofc it only works well from one direction....once you move to the opposite side of the mouse over object it gets way off.

    does someone have some advice? or a better way?
    this is not an overlay scene text, but in the main scene(main scene is different for every one I guess ) this is the gameplay scene...
    Last edited by JustinBarrett; 12-Aug-17 at 10:14.
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



  2. #2
    Member sdfgeoff's Avatar
    Join Date
    May 2010
    Location
    Where the best chocolate comes from
    Posts
    4,976
    once you move to the opposite side of the mouse over object it gets way off.
    ???

    I use the FontObject's dimension property, and offset by half of that. You also need to respect it's original position (probably), so be sure to store that somewhere. I should probably make an UPBGE component for this, as it is quite a common thing and being able to apply it to a text object without thinking would be amazing.
    Code:
    width = self.obj.dimensions.x
    self.obj.localPosition.x = self.start_position - width / 2
    "Someone applied a roof texture to that wall" - martinsh

    Website: www.sdfgeoff.space



  3. #3
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888
    WOW, I am an idiot...always overlooking the obvious. thanks.
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



  4. #4
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888
    no actually, it changes based on players viewing orientation...I'll figure it out though. I just thought there would be a quick fix without having to 'think'
    I still thank you for the 'dimension' attribute...I was unaware of it. been using min max stuff this whole time
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



  5. #5
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888
    I'm just going to move it to the overlay scene...I've been planning on doing that anyway due to practical uses and overlay issues...

    Opening a ticked, or bringing it up would be good(UPBGE team). It is documented to use alignment via a list, but it does not seem to work...I cannot remember the code I had for it off the top of my head...but it was something like 'txt.text_alignment[0]' or something...cannot remember...it may have even been multi dimensional for vertical and horizontal.
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



  6. #6
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888
    So I have it working, but doing it in an overlay scene makes it a lot less complicated...people just need to remember to update the text before the conversion(division)

    this is only for those who may look this up 'googling' it etc.

    Code:
    txt.text = 'some string'#make sure this is updated first or it will not center correctly
    w_X = txt.dimensions.x / 2
    txt.worldPosition = mouse.hitPosition# just an example any vector3 should work.
    txt.localPosition.x = mouse.hitPosition.x - width
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



  7. #7
    Member BluePrintRandom's Avatar
    Join Date
    Jul 2008
    Location
    NoCal Usa
    Posts
    17,997
    I use similar math and use a parent box object,
    I measure using text.dimensions, unparent the text and then scale the hitbox
    then use

    Text.worldPosition= hitBox.worldPosition+(hitBox.worldOrientation*Vect or([-dimension.x*.5,0,0])

    then reparent.

    you can load a string using mouseOverHitBox and use it to call a function using a dictionary you construct,

    command = dict[moa.hitObject['prop']]
    data = moa.hitObject['SomeOtherProp']
    command(data)


    this way a single mouse over sensor can interact with many gui elements etc.
    Last edited by BluePrintRandom; 12-Aug-17 at 16:43.
    Break it and remake it - Wrectified
    If you cut off a head, the hydra grows back two.
    "headless upbge"



  8. #8
    Member JustinBarrett's Avatar
    Join Date
    Jul 2009
    Location
    Trier(near), Germany
    Posts
    1,888
    it is a single sensor, and single text object I already have 2 mouse over sensors running(per scene) and that is enough
    "The crows seem to be calling my name." Thought Kaw.
    Project Valiant



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •