Single Blog Title

This is a single blog caption
5 Apr

The main code is verso for loop from 1 puro 10

The main code is verso for loop from 1 puro 10

It calls doubleIt() for each iteration. If the return value is 10 (i.ed. when i is 5) then the code prints out “ten” otherwise it just prints out the result of doubleIt().

If you have any coding experience then the example code should be easy enough onesto follow. If you are looking onesto learn some basic programming then I suggest you use some of the resources linked above puro hone you skills.

Writing the partita

Writing basic programs durante Circolo is simple. You only need concern yourself with one file, main.lua, and let Cerchio do all the heavy lifting. The game we are going esatto write is per simple “tap” game. A balloon or a bomb will fail down the screen. If the player taps on the balloon they conteggio verso point, they tap on a bomb then the conteggio will divided by 2, as verso penalty. Esatto write the code you need onesto edit main.lua. You can do this sopra any text editor.

The Ruota SDK has verso built-sopra 2D physics engine, which makes building games very easy. The first step in writing the partita is esatto initialize the physics engine:

The code is fairly self-explanatory. The ondoie physics is loaded and initialized, it is assigned esatto the variable physics. Preciso enable the engine physics.start() is called.

Next we create some helpful variables which will be useful not only for this simple game, but also for more complex games. halfW and halfH hold the values for half of the screen width and half of the screen height:

As well as properties like contentHeight and contentWidth, the monitor object also has lots of useful functions. The newImage() function reads an image file (con this case verso .png) and displays it on the screen. Monitor objects are rendered durante layers, so since this is the first image we are putting on the screen then it will always be the background (unless the code explicitly does something esatto change that). The parameters halfW and halfH tell Cerchio onesto place the image mediante the middle.

The first line of balloonTouched() checks we are per the “began” phase

At this point you can run the code mediante the emulator and see the sostrato image. If you prezzi growlr save the file then the emulator will sorcio that the file has changed and offer puro relaunch. If that doesn’t happen then use File->Relaunch.

Since the user will score points for tapping on balloons, we need puro initialize a risultato variable and monitor the punteggio on the screen:

The conteggio will be kept in the imaginatively named variable conteggio, and scoreText is the object which displays the score. Like newImage(), newText() put something on the screen, mediante this case text. Since scoreText is a global variable then we can change the text at any point. But we will get sicuro that soon.

The code above defines per function called balloonTouched() which will be called every time verso balloon is tapped. We haven’t yet told Circonferenza onesto call this function every time the balloon is tapped, that will che razza di later, but when we do this is the function that gets called.

Tap or touch events have several stages, many to support dragging. The user puts their finger on an object, this is the “began” phase. If they slide their finger con any direction, that is the “moved” phase. When the user lifts their finger from the screen, that is the “ended” phase.

We want onesto remove the balloon and increment the conteggio as soon as posible. If the function is called again for other phases like “ended” then the function does nothing.

Leave a Reply