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

2019/3/26

Stacking objects in game

jajankens jajankens

2019/3/26

#
Hello, I'm working on a game where I catch a butterfly with a net, at which point it stacks the butterflies on top of each other on the back end of my skateboard (that moves with my catcher using the left and right keys). I was able to program the catch behavior between the net/butterflies using the isTouching and removeTouching functions, but I'm stumped as to how I'd get the butterfly sprites to stack on the back of the skateboard. I was thinking setLocation might be the answer, but its parameters require x and y values, and the x value of my skateboard would be changing as I move it left/right, so I'm not sure how/if that would work. Could someone point me in the right direction? Thank you!
Super_Hippo Super_Hippo

2019/3/27

#
You can set the location of the butterfly sprites from the skateboard class, so the skateboard object can set the butterfly's location in relation to its own location. If they are just images moving with the skateboard without any other purpose, then you can create a new simple actor and assign an image to it. Then move it accordingly. You could also have one actor to display any number of butterflys if you change the image (and position) based on the number of collected butterflys. It is a bit similar when you create an object in relation to an object's position, for example when an object shoots a projectile. But you need to keep a reference to the created object, so you can move it with the skateboard.
You need to login to post a reply.