masterYao09
masterYao09

Reputation: 15

how do you make a Rectangle change it's position or move?

I'm using rectangles for collision detection and a rectangle is created every 3 seconds, I wan't the rectangle to move upward just like my sprite but .translateY() method can't be used on rectangle.

this is what I did to my sprites stored on ArrayList:

for(Sprite sprite:mySprite){
    sprite.translateY(deltaTime*movementSpeed);
}

and this is what I did on rectangles which does not work:

for(Rectangle rect:myRect){
    rect.setY(deltaTime*movementSpeed);
}

Upvotes: 0

Views: 817

Answers (1)

Angel Angel
Angel Angel

Reputation: 21658

it is possible that your rectangle is being drawn in poscición you tell them, but setY is not the same, which translateY, simple explanation:

if for example deltaTime = 1 aprox. and movementeSpeed = 5. you always drawing the rectangle in the same position, with minimal variation in delta maybe just not appreciated:

your position is rect.setY(5); all time.

try this

for(Rectangle rect:myRect){
    rect.setY(rect.getY() + (deltaTime*movementSpeed));
}

I hope this help.

Upvotes: 1

Related Questions