The main code is a for loop from 1 esatto 10

The main code is a for loop from 1 esatto 10

It calls doubleIt() for each iteration. If the return value is https://datingranking.net/it/amor-en-linea-review/ 10 (i.di nuovo. 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 to follow. If you are looking esatto learn some basic programming then I suggest you use some of the resources linked above onesto hone you skills.

Writing the game

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

The Disco SDK has verso built-mediante 2D physics engine, which makes building games very easy. The first step mediante writing the partita is puro initialize the physics engine:

The code is fairly self-explanatory. The module physics is loaded and initialized, it is assigned to the variable physics. Onesto enable the engine physics.start() is called.

Next we create some helpful variables which will be useful not only for this simple partita, 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 schermo object also has lots of useful functions. The newImage() function reads an image file (con this case per .png) and displays it on the screen. Display objects are rendered con layers, so since this is the first image we are putting on the screen then it will always be the retroterra (unless the code explicitly does something sicuro change that). The parameters halfW and halfH tell Circonferenza to place the image con the middle.

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

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

Since the user will conteggio points for tapping on balloons, we need onesto initialize a risultato variable and schermo the risultato on the screen:

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

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

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

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

This entry was posted in Uncategorized and tagged . Bookmark the permalink.