[SPOUT] Move Label over time ?

Discussion in 'Plugin Development' started by r3Fuze, Aug 29, 2011.

Thread Status:
Not open for further replies.
  1. For hours i've tried to make a label move over time but without result.

    This is the closest i came to making it move:
    Code:
    public static void moveText(final Widget widget, int x, int y, final SpoutPlayer sp) {
        for (int i = 1; i < 11; i++) {
            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            public void run() {
                widget.setX(widget.getX() + 2);
                System.out.println("x" + widget.getX() + "y" + widget.getY());
                widget.setDirty(true);
            }
            }, 3 * 10L);
        }
        }
    If someone can help me, i would appriciate it!
    @SpoutDev
    @Afforess
     
  2. Offline

    Baummann

    sp.getMainScreen().updateWidget(widget);
     
  3. @Baummann
    Doesn't work :/

    EDIT: I dont see how it wouldn't work....
     
  4. Offline

    Baummann

    player.getMainScreen().removeWidget(widget);
    player.getMainScreen().updateWidget(widget);
    player.getMainScreen().addWidget(widget);
    player.getMainScreen().updateWidget(widget);
    maybe that works
     
  5. Offline

    Afforess

    Need to see a bit more code - where did you attach it?
     
  6. This is the class where its in:
    Code:
    package com.fuze.Gui.utils;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    import org.bukkit.entity.Player;
    import org.getspout.spoutapi.gui.Color;
    import org.getspout.spoutapi.gui.GenericButton;
    import org.getspout.spoutapi.gui.GenericLabel;
    import org.getspout.spoutapi.gui.GenericPopup;
    import org.getspout.spoutapi.gui.Label;
    import org.getspout.spoutapi.gui.Widget;
    import org.getspout.spoutapi.player.SpoutPlayer;
    
    import com.fuze.Gui.Gui;
    
    public class ScreenUtil {
        static Gui plugin;
        public static HashMap<UUID, String> buttons = new HashMap<UUID, String>();
        public static HashMap<UUID, String> textfields = new HashMap<UUID, String>();
    
        public ScreenUtil(Gui instance) {
        plugin = instance;
        }
    
        @SuppressWarnings("deprecation")
        public static void addText(Color color, String text, int x, int y, SpoutPlayer sp) {
        Label spouttext = new GenericLabel("");
        spouttext.setTextColor(new Color(color.getRedF(), color.getGreenF(), color.getBlueF(), color.getAlphaF()));
        spouttext.setX(x).setY(y);
        spouttext.setText(text);
        sp.getMainScreen().attachWidget(spouttext);
        }
    
        @SuppressWarnings("deprecation")
        public void addText(Color color, String text, int x, int y, int time, SpoutPlayer sp) {
        Label spouttext = new GenericLabel("");
        spouttext.setTextColor(new Color(color.getRedF(), color.getGreenF(), color.getBlueF(), color.getAlphaF()));
        spouttext.setX(x).setY(y);
        spouttext.setText(text);
        sp.getMainScreen().attachWidget(spouttext);
        moveText(spouttext, sp);
        removeText(spouttext, time, sp);
        }
    
        public static void removeText(final Widget widget, int time, final SpoutPlayer sp) {
        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            public void run() {
            sp.getMainScreen().removeWidget(widget);
            }
        }, time * 20L);
        }
    
        public static void moveText(final Widget widget, final SpoutPlayer sp) {
        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            public void run() {
            widget.setX(widget.getX() + 2);
            widget.setDirty(true);
            sp.getMainScreen().updateWidget(widget);
            System.out.println("x" + widget.getX() + "y" + widget.getY());
            }
        }, 3 * 10L);
        widget.setX(widget.getX() + 2);
        widget.setDirty(true);
        sp.getMainScreen().updateWidget(widget);
        System.out.println("x" + widget.getX() + "y" + widget.getY());
        }
    }
    
     
  7. Offline

    Top_Cat

    While I dislike some of your coding practices such as lack of indentation, ignoring/suppressing important warnings and not using shiftXpos.

    Disregarding this I believe the reason you are not getting the desired result is that scheduleSyncDelayedTask is only called once whereas you want it to move 2 at regular intervals for which you need a scheduleSyncRepeatingTask and a way to cancel it when you're done.
     
Thread Status:
Not open for further replies.

Share This Page