1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

FloatingTextParticle bug

Discussion in 'Development' started by SergeyIvanov, Jun 19, 2017.

  1. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    Hi, I have a problem with the flying text, when I create the text for some reason they merge into one.

    My code:
    PHP:
            $this->pg->getServer()->getDefaultLevel()->addParticle(new FloatingTextParticle(new Vector3(282 0.578173 0.5), """§3-x-"), [$event->getPlayer()]);
            
    $this->pg->getServer()->getDefaultLevel()->addParticle(new FloatingTextParticle(new Vector3(282 0.577 0.75173 0.5), """§3-x§6 Кальян§3 x-"), [$event->getPlayer()]);
            
    $this->pg->getServer()->getDefaultLevel()->addParticle(new FloatingTextParticle(new Vector3(282 0.577 0.50173 0.5), """§3-x§e Чтобы затянуться, нажми по"), [$event->getPlayer()]);
            
    $this->pg->getServer()->getDefaultLevel()->addParticle(new FloatingTextParticle(new Vector3(282 0.577 0.25173 0.5), """§3-x§e кальяну§7 (варочной стойке)§3 x-"), [$event->getPlayer()]);
            
    $this->pg->getServer()->getDefaultLevel()->addParticle(new FloatingTextParticle(new Vector3(282 0.577173 0.5), """§3-x-"), [$event->getPlayer()]);
     

    Attached Files:

  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    Make the differences of the Y coordinates larger. I think the floating text is superimposed
     
  3. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    I need to flying text was nearby.
     
  4. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Are you trying to have multiple lines of text? You could use linebreaks instead of spawning multiple ones manually.
     
    XdmingXD and Muqsit like this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Okay, I have said this before and I'll say it again. Try not to rewrite the same line over and over again. That will make things easier for you to understand and you won't feel mad while going through a bunch of numbers. I assume you are a beginner so that should be a good tip for you. Use loops. Often people refer to loops as lag function, but don't listen to that BS.
    What you write could be written in a better way. (Technically, anything anyone writes could be written in a better way; my way of dealing with this would be different from many and probably not the best too).
    What you want to write is a simple, understandable and easily modifiable code.
    PHP:
    /** @var Vector3 $pos */
    foreach([
        
    "Line 1",
        
    "Line 2",
        
    "Line 3",
        
    "Line 4"
    ] as $line) {
        
    $pos $pos->subtract(00.25); //distance between each line is 0.25 off the Y coordinate of the previous line
        
    $particle =  new FloatingTextParticle($pos""$line);
        
    $player->getLevel()->addParticle($particle, [$player]);
    }
     
    Hipster likes this.
  6. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You'd be better off using a for or while loop:
    PHP:
    // For:
    for($i 1$i <= 4$i++) {
        
    $line "Line $i";
        
    $pos $pos->subtract(00.25); //distance between each line is 0.25 off the Y coordinate of the previous line
        
    $particle =  new FloatingTextParticle($pos""$line);
        
    $player->getLevel()->addParticle($particle, [$player]);
    }

    // While:
    $i 1;
    while(
    $i <= 4) {
        
    $line "Line $i";
        
    $pos $pos->subtract(00.25); //distance between each line is 0.25 off the Y coordinate of the previous line
        
    $particle =  new FloatingTextParticle($pos""$line);
        
    $player->getLevel()->addParticle($particle, [$player]);
    }


    Note to self: read the thread properly next time before writing a stupid answer that is completely irrelevant.
     
    Last edited: Jun 20, 2017
    Awzaw likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.