Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Not allowing a sprite to move while camera moves
- danilovescatz
- New to Scratch
1 post
Not allowing a sprite to move while camera moves
Hello everybody, I am currently working on a game for my research project and I am in need of some help. I added some trees to my map (every tree is a separate sprite, I do not know a better way to do this.) and coded the player so that they cannot pass the tree. Now, I just added the feature where it seems like the “Camera” is following the player, this was very nice and good to do but now the problem lies in that every single tree does not move in accordance with the map, by this I mean that they stay in place when the map is moving, and since the map is added as a sprite and not a backdrop I am finding it extremely hard to find a way to make the trees move with the map. Could anyone help me please?
- helloworldbyeworld
- Scratcher
1000+ posts
Not allowing a sprite to move while camera moves
Make variables to store the camera x and y. You can put something like this in each of the trees:
when green flag clicked
forever
go to x: ((initial x position of tree::grey) - (camera x)) y: ((initial y position of tree::grey) - (camera y))
if <<<(x position) > (240)> or <(x position) < (-240)>> or <<(y position) > (180)> or <(y position) < (-180)>>> then
hide
else
show
end
end
Helloworldbyeworld | 1200+ posts
Have a great day
- Discussion Forums
- » Help with Scripts
- » Not allowing a sprite to move while camera moves