

Let's explain these two lines in a little more detail: Below the previous lines, add these commands: local physics = require( "physics" ) While using physics is not required to make a game, it makes it much easier to handle many game situations. Time to get into physics! Box2D is the included physics engine for your use in building apps and games. When you specify the values ntentCenterX and ntentCenterY, Solar2D will set the center coordinates of the screen as the background.x and background.y properties. By changing the object's x and y properties, however, we can move the background image to a new location.įor this project, we'll place the background in the center of the screen - but what if we don't know exactly which coordinate values represent the center? Fortunately, Solar2D provides some convenient shortcuts for this. Immediately following the line you just entered, add the two highlighted commands: local background = display.newImageRect( "background.png", 360, 570 )īy default, Solar2D will position the center of an object at the coordinate point of 0,0 which is located in the upper-left corner of the screen. The final step for the background is to position it at the correct location on the screen. In this case, we'll simply use the image's pixel dimensions, although as noted above, display.newImageRect() allows you to resize/scale the image via these numbers. The next two parameters, 360 and 570 specify the size that we want the background image to be. The specified name must match the actual file name exactly, including case-sensitive matching! For instance, if the actual file name is background.png, do not enter it as "BackGround.PNG". In this case, that value will be an image used as your background. A variable, just like you learned in math class, is used to store a value. The first word, local, is a Lua command indicating that the next word will be a variable.There are a several aspects involved with this command. Local background = display.newImageRect( "background.png", 360, 570 ) In this a file, type in the highlighted command:. This is the Lua file with which the application starts, every time you run the app. The a file is the foundational "core program file" of every Solar2D project and you cannot create an app without it. Using your chosen text editor, locate and open the a file within your project folder. While there are ways to change the layering order of images and send them to the back or front of the display stack, we'll keep this project simple and load them in a logical order. Solar2D places everything on the screen from back to front in regards to layering, so the first image we load will exist behind other images that are loaded afterward. The first image that we need to load is the background.
