The SpriteAnimation class has a *removeOnFinish* boolean that you can set in the Fruit collision code to have it automatically remove the component when the animation finishes.
Hi, I really like this series. And I think that you have a great approach to teaching. About the remove after pickup on the fruit. The class SpriteAnimationComponent has a variable called removeOnFinish. It only removes if animation(loop: false). So if fruit constructor is changed to: ``` Fruit({this.fruit = 'Apple', position, size}) : super(position: position, size: size, removeOnFinish: true); ``` The fruit will be removed once collected and collection animation is done. Keep up the good work :)
Glad you've been enjoying the series. I appreciate the feedback, I actually noticed that method later on and wondered if it worked like that. Glad to know it does, thanks 😊
Hi again! Just finished this chapter. Happy that my code didn't complain adding these collectibles 🎉(given the approach that I used for player/blocks collisions) About the animation thing at the end, I found in the docs the animationTicker property, it can be used to know the state of the animation including if it is finished (non looping) using its attribute completed. It is a future so await/async is required. Thanks for your effort!
BTW, I liked your approach with the collision code in the fruit side. I would like to do the same for the blocks to make the player code shorter but now I'm scared of touching that code 😂
Again, great series. I think you can greatly simplify the scrolling background by using the supplied Parallax component (even if it is only one layer): ``` final background = ParallaxComponent( priority: -1, parallax: Parallax( [ ParallaxLayer( ParallaxImage( game.images.fromCache('Background/$backgroundName.png'), repeat: ImageRepeat.repeat, fill: LayerFill.none, ), ), ], baseVelocity: Vector2(0, -50), ), ); add(background); ``` And you wouldn't need the background.dart component at all.
Great video! Regarding the loop on the background, you could make it like this on the update function: if (position.y > tileSize * scrollHeight) { position.y -= tileSize * scrollHeight; } Then there would be no need for you to alter the Y value for loop on level! I've been learning a lot from you, thank you!
I didn't realize at first that you added a super chat as it looked different on mobile. I wanted to reply again to say thank you so much, I really appreciate you doing that. I'm glad the video was helpful 😊
I'm enjoying the series. So far I learned a lot, Thanks man. about looping background the problem in floor() as you said in video if you try using round() instead of floor() it works
27:20 I think you only need to add 1 row in the for loop like y < numTilesY + 1 and it still works, because you've subtracted 1 row in the position (-tileSize). You can check by doing y < numTiles - 1 and it will lose 2 rows. Hope that makes sense. Btw, I love this series.
When i collide with fruit it doesn't go in to that 'other is fruit' if statement, but when i print out 'other' in this method, it showed me that this is fruit. What should I do?
I used it so I could only collect it once. If I remember correctly it would cause me to collect it multiple times otherwise. It's been awhile though so I could be wrong lol
My collidedWithPlayer-Methode detects a collision at the start. The Player collides with all fruits one time at the beginning. I dont know why?! Anyone the same problem or a solution?
Hi, it's just a try, but did you remove the function from the onLoad() method? If you don't remove it from there every time the level is rendered it will call the function and change the state of the fruit (consequently it will disappear)
27:22 I think the reason why it works can be explained by the following algebraic demonstration. For the sake of this proof I´m assuming game.size.y % tileSize = 0 (meaning the height of our game can be perfectly divided by the tile size). numTilesY = game.size.y / tileSize; loopCondition = game.size.y / numTilesY; // This is the loop condition you have on line 41 // Replacing "numTilesY" in "loopCondition" with its value "game.size.y / tileSize": loopCondition = game.size.y / numTilesY; loopCondition = game.size.y / (game.size.y / tileSize); // Dividing by a fraction is equivalent to multilying by its reciprocal loopCondition = game.size.y * (tileSize / game.size.y); // We move the parenthesis loopCondition = (game.size.y * tileSize) / game.size.y; // We can cancel "game.size.y" loopCondition = tileSize; So, the amount of rows you are rendering equals the tile size, and this amount is way larger than the actual amount of rows required for filling the screen (unless you had a screen that required over 64 rows). Then, on first render, the "update" function in the "BackgroundTile" class translates all the extra rows back to "position.y = -tileSize;". In a nutshell, this works cause you are rendering way more rows than needed, and all extra rows are getting stacked into one single row on first render. Loving the series, keep on the good work.
We can easily check this by counting how many times you enter on the outter loop in line 41, you'll see it equals tileSize - 1 (cause the final iteration breaks the loop)
The SpriteAnimation class has a *removeOnFinish* boolean that you can set in the Fruit collision code to have it automatically remove the component when the animation finishes.
Ahh, good to know
Hi, I really like this series. And I think that you have a great approach to teaching.
About the remove after pickup on the fruit. The class SpriteAnimationComponent has a variable called removeOnFinish. It only removes if animation(loop: false). So if fruit constructor is changed to:
```
Fruit({this.fruit = 'Apple', position, size})
: super(position: position, size: size, removeOnFinish: true);
```
The fruit will be removed once collected and collection animation is done.
Keep up the good work :)
Glad you've been enjoying the series. I appreciate the feedback, I actually noticed that method later on and wondered if it worked like that. Glad to know it does, thanks 😊
Love your work spellthorn💖. Ive learnt sooooo much
Hi again! Just finished this chapter. Happy that my code didn't complain adding these collectibles 🎉(given the approach that I used for player/blocks collisions)
About the animation thing at the end, I found in the docs the animationTicker property, it can be used to know the state of the animation including if it is finished (non looping) using its attribute completed. It is a future so await/async is required. Thanks for your effort!
BTW, I liked your approach with the collision code in the fruit side. I would like to do the same for the blocks to make the player code shorter but now I'm scared of touching that code 😂
Haha. Touch you must. Oh thats good to know I'm tired of counting the time of the animation 🤣 Guess what I get for not reading the documentation 🤫
Thanks man ,my bro, you explain a lot ,really helps me a lot to learn flame flutter,Big Respect :D
Again, great series. I think you can greatly simplify the scrolling background by using the supplied Parallax component (even if it is only one layer):
```
final background = ParallaxComponent(
priority: -1,
parallax: Parallax(
[
ParallaxLayer(
ParallaxImage(
game.images.fromCache('Background/$backgroundName.png'),
repeat: ImageRepeat.repeat,
fill: LayerFill.none,
),
),
],
baseVelocity: Vector2(0, -50),
),
);
add(background);
```
And you wouldn't need the background.dart component at all.
Yea I figured that out later on. Thanks for the help 🙂
Great video! Regarding the loop on the background, you could make it like this on the update function:
if (position.y > tileSize * scrollHeight) {
position.y -= tileSize * scrollHeight;
}
Then there would be no need for you to alter the Y value for loop on level!
I've been learning a lot from you, thank you!
Thanks for the tips! I believe I fix this in the future episode with bug fixes 😊
Im enjoying the series. So far I learned alot, Thanks man.
Glad you enjoy it!
Great videos, thanks!
Thank you, glad you enjoyed it 😊
I didn't realize at first that you added a super chat as it looked different on mobile. I wanted to reply again to say thank you so much, I really appreciate you doing that. I'm glad the video was helpful 😊
I'm enjoying the series. So far I learned a lot, Thanks man.
about looping background the problem in floor() as you said in video if you try using round() instead of floor() it works
Thank you , You'r great teacher!!
Thanks 😊 glad you're enjoying the series
Awesome tutorial as usual
Thank you 😊
27:20 I think you only need to add 1 row in the for loop like y < numTilesY + 1 and it still works, because you've subtracted 1 row in the position (-tileSize). You can check by doing y < numTiles - 1 and it will lose 2 rows. Hope that makes sense.
Btw, I love this series.
Thanks for the information, I'll look into it. I'm glad you're enjoying the series 😁 more to come!
You're correct, he's missing one row by not setting the loop condition to
Thanks for this, we use a better way in a future episode though where loops not even needed 😁
Thank you for the video. really helpful for me.
You are welcome! I'm glad it was helpful 😁
When i collide with fruit it doesn't go in to that 'other is fruit' if statement, but when i print out 'other' in this method, it showed me that this is fruit. What should I do?
54:00 I fixed it just with amount: 7 in the animation, in this way the last frame is empty!! [And no removeFromParent needed]. It's a correct way?
Works amazig. Thanks 🫡
Thanks 😊
what is benefit of using bool _collected variable?
I write the collisionWithPlayer func without _collected variable and it run.
I used it so I could only collect it once. If I remember correctly it would cause me to collect it multiple times otherwise. It's been awhile though so I could be wrong lol
My collidedWithPlayer-Methode detects a collision at the start. The Player collides with all fruits one time at the beginning. I dont know why?! Anyone the same problem or a solution?
Solution: I have forgotten to remove this methode from the onLoad()-Methode in Fruite ;-)
Hi, it's just a try, but did you remove the function from the onLoad() method? If you don't remove it from there every time the level is rendered it will call the function and change the state of the fruit (consequently it will disappear)
Just curious, do y'all go through all this when creating the many developers make the same video vids😅
So I make what I'm trying to make, figure it out then figure out how to improve it. Then figure out how to explain it then record the video. Lol
🎉🎉🎉🎉🎉🎉
😁
😇😇😇
😁
im at this section and runs soo slow
Probably because of how I did the scrolling. I improved it later in the series so maybe skip that for now
27:22 I think the reason why it works can be explained by the following algebraic demonstration.
For the sake of this proof I´m assuming game.size.y % tileSize = 0 (meaning the height of our game can be perfectly divided by the tile size).
numTilesY = game.size.y / tileSize;
loopCondition = game.size.y / numTilesY; // This is the loop condition you have on line 41
// Replacing "numTilesY" in "loopCondition" with its value "game.size.y / tileSize":
loopCondition = game.size.y / numTilesY;
loopCondition = game.size.y / (game.size.y / tileSize); // Dividing by a fraction is equivalent to multilying by its reciprocal
loopCondition = game.size.y * (tileSize / game.size.y); // We move the parenthesis
loopCondition = (game.size.y * tileSize) / game.size.y; // We can cancel "game.size.y"
loopCondition = tileSize;
So, the amount of rows you are rendering equals the tile size, and this amount is way larger than the actual amount of rows required for filling the screen (unless you had a screen that required over 64 rows). Then, on first render, the "update" function in the "BackgroundTile" class translates all the extra rows back to "position.y = -tileSize;".
In a nutshell, this works cause you are rendering way more rows than needed, and all extra rows are getting stacked into one single row on first render.
Loving the series, keep on the good work.
We can easily check this by counting how many times you enter on the outter loop in line 41, you'll see it equals tileSize - 1 (cause the final iteration breaks the loop)
Makes sense, we fix all this in episode 8 though as there is a better built in way, oops