This site requires JavaScript, please enable it in your browser!
Greenfoot back
Paul12345
Paul12345 wrote ...

2020/10/31

Making actors stay on top of each other (overlay)

Paul12345 Paul12345

2020/10/31

#
I have a scrolling world and I want an Actor to stay on top of another when it's moving.
    @Override
    public void setLocation(int x,int y)
    {
        super.setLocation(x,y);
        text.setLocation(x,y);
    }
In this case I want the text to stay on top of my object, implementing it this way is very "jiggly", the text location doesn't update fast enough I guess, so it doesn't look smooth at all, any recommendations for making it seem more flawless and smooth?
danpost danpost

2020/10/31

#
Please provide method code where these actors are initially added into the world.
Paul12345 Paul12345

2020/10/31

#
danpost wrote...
Please provide method code where these actors are initially added into the world.
This is the constructor of my world
    public Background()
    {    

        super(1000, 600, 1,false); 
        scroller = new Scroller(this);
        rbt = new RBTree(this);
        addObject(rbt,0,0);
        ib=new InsertButton(70,25);
        addObject(ib,900,500);
        addObject(ib.getTextBox(),750,500);
        addObject(ib.getText(),750,500);
        rb1=new NodeRB(1502);
        addObject(rb1,100,100);//Here I Add the base Object
        addObject(rb1.getText(),100,100);//Here I add the Component Object on top of the base Object
        

    }
danpost danpost

2020/10/31

#
Adding looks okay. Do you have an act method in your NodeRB class (if not, a class it extends)? Show, if so.
Paul12345 Paul12345

2020/10/31

#
danpost wrote...
Adding looks okay. Do you have an act method in your NodeRB class (if not, a class it extends)? Show, if so.
I realized my mistake. Since i was updating the locations of all objects in my WorldScrolling method I didn't have to update my text location in my NodeRB also, since it was already added in the world over it. Thank you for your feedback though !
You need to login to post a reply.