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

2021/10/24

Trouble moving individual objects

star101 star101

2021/10/24

#
public void act()
    {
        tme++;// counts how many acts
        note0 = new Note();
        note1 = new Note();
        note2 = new Note();
        note3 = new Note();
        note4 = new Note();
        
        if(tme % 100 == 0)
        {
           addObject(note0, 480, 348);
           note0.setImage("note"+0+".png");
           addObject(note1, 559, 348);
           note1.setImage("note"+1+".png");
           addObject(note2, 600, 348);
           note2.setImage("note"+2+".png");
           addObject(note3, 650, 348);
           note3.setImage("note"+3+".png");
           addObject(note4, 711, 305);
           note4.setImage("note"+4+".png");
           note1.setRotation(90 + degree);
           note1.move(1);
           note1.setRotation(0);
        } 
        note0.setRotation(90);
        note0.move(15);
        note0.setRotation(0);
        note1.setRotation(90);
        note1.move(15);
        note1.setRotation(0);
        note2.setRotation(90);
        note2.move(15);
        note2.setRotation(0);
        note3.setRotation(90);
        note3.move(15);
        note3.setRotation(0);
        note4.setRotation(90);
        note4.move(15);
        note4.setRotation(0);
    }
having trouble moving each object individually, this is in the world class( I know it looks weird in terms of how the movement is happening, I am going to be moving them at different angles later and thats why it looks odd) my problem is in this state non of them move
RcCookie RcCookie

2021/10/25

#
I suppose you are trying to move the Note objects each frame, but right now you are creating new ones every frame and each new one gets moved once, immediately. In that case the movement code should probably go into the Note class rather into the world class. For example:
public class Note extends Actor {

     // ...

    public void act() {
        setRotation(90);
        move(15);
        setRotation(0);

        // Which is actually equivalent to:
        setLocation(getX(), getY() + 15);
    }

    // ...
}
star101 star101

2021/10/25

#
my problem is that, at the moment they are each doing the same movement but I will change that later and if I put it in the Actor class they all must move the same way
danpost danpost

2021/10/25

#
star101 wrote...
my problem is that, at the moment they are each doing the same movement but I will change that later and if I put it in the Actor class they all must move the same way
Lines 4 thru 8 are executed every act step. Therefore, on act steps that do not have tme%100 equal to 0, you are not working with the actors in the world in lines 26 thru 40. Note: I am kind of surprised that you are not getting errors on the move lines between 26 and 40 as the actors should be in the world for move to find their locations in the world. Create the Note actors in your world constructor instead of in the act method. You have this (with similar for the other actors):
note0.setRotation(90);
note0.move(15);
note0.setRotation(0);
No rotation will ever show as act happens between frames and the last set rotation for each actor is 0 for each frame. You might try:
note0.turn(90);
note0.move(15);
You need to login to post a reply.