Image Sprite falling

Hello,

i need a method for drop a Image Sprite in a Canvas like falling.
I want to drop a ball when I have placed it and let it go.

I hope you can help me.

Thanks.

Do you want to drop from top to bottom or more like 3d into the screen?

2 Likes

The simplest form is this when dropping from top to bottom.

image

5 Likes

Hey Peter,

I would like to make it so that the ball falls and if it hits an obstacle it should bounce off and in the end this ball falls into a container at the bottom.

There it should then be checked in which container it fell and how many points this gives.

Like this:
conzept_fb

I think maybe @italo can help you with this one.

3 Likes

Should I write to him privately or do you think he will answer here as soon as he has time? :slight_smile:

1 Like

I would just be patient.

1 Like

I just woke up (7:20 am here) :grin:
I’ll see what I can do with that. Like @Peter said, be patient. :wink:

5 Likes

you also can find a lot of ideas how to do things around canvas and sprites in Scott’s library here Google Groups

Taifun

1 Like

I finally got some time to sit in the computer. I’m researching into this a little bit, but if you are really interested in, I would suggest you to do the same (research) because this is not so simple to do for beginners. I could come up with a basic demo of this but you will have to adapt it and keep adding to it on your own.
Start reading and trying stuff on a canvas component with sprites and balls, also check the link @Taifun gave you in the previous post or search on YouTube for programming ball bouncing or similar subjects. I can’t promise you a date or time when I will have some blocks to show here.

6 Likes

This is the bouncing only, I tried but I can’t get to simulate gravity with my limited knowledge, so that will be your part in it. I think this will be a good start for what you want to do.


BallFall.aia (19.4 KB)

3 Likes

For gravity, see Scott Ferguson’s demos on the AppInventor Google groups forum

2 Likes

Thank you so much for this demo.
One question about “Ball.Y of component” section.
How can i find this?

1 Like

image

2 Likes

Thank you very much.
You all helped me a lot.

2 Likes

I think it simple just do it by point whre do you want ball go

Maybe you can show an example?

Yes, as you can see, there’s two ways of making a sprite move in Kodular.

  1. By calculating the sprite x and y in every frame with a clock. That’s how usually is done in other programming languages and it can be done in Kodular as well.
    Pros: You have more control over the movement of the object and is more precise.
    Cons: Speed! To calculate each x and y of the object takes more processing time, specially if your movement is not linear and/or includes complex calculations like bouncing, gravity, friction, etc. You need to use at least one clock component for using this method.

  2. By giving the sprite a heading and a speed. The instant you give it a speed > 0, the object starts moving in the direction of the heading (angle) without having to do anything (no calculating what x or y is next!).
    Pros: SPEED! Each sprite has its own clock in the back and you don’t have to even worry about it.
    Cons: Not very precise movements. You have to constantly adapt the trajectory and speed of the sprite to make it move the way you want.

If you compare both methods to real life, they will be like 1. Stop motion movies, where you move the object frame by frame and take a picture of it. And 2 is like pushing a ball and from time to time give it a little tap here and there to make it go where you want, without stopping it.

In the end it depends on what kind of app you are making and how you feel more comfortable working. For an app that has a lot of stuff moving at the same time, I would use method 2. If there’s only one or two sprites moving, it’s ok to use method 1.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.