Why do we need background?
Background makes game more interactive, and it also provides nice looks to game, imagine you are playing a 2d carom game now what if there is no scoreboard showing in background on your screen? Or what if only striker will move on the screen and there won't be any board at background? I guess will be hard to understand game, that's why background is needed. However, we are going to add a background in this game for collision detection purpose for the platformers.
Steps
Add the background image to your assets folder
Add background image to your assets folder like added boy and girl pic and register to pubspec file. I am adding two image one is background and other is platform basically I want to make game in which there is background and game character can jump on the platform.
In the onload method, first load the image sprite and we will add some properties onto the image sprite with the cascade operator as used before. We are going to add the size of the platform sprite on which the girl will stand.
as the sprites are in layers, we are also going to move the platform down below in the codebase below the background.
So the following video is the output of today's blog.
In the upcoming blog, we will implement collision.
Refer to the link below in case you get any doubt in code.
https://gitlab.com/mdnazisharman/addingbackground/-/tree/main