µLua DS - Forum officiel | Official forum Forum Index

µLua DS - Forum officiel | Official forum
Le bon endroit pour en savoir plus sur MicroLua et pour parler de vos projets ! | The right place to learn more about MicroLua and talk about your projects !

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Official Tutorials Translated!
Goto page: 1, 2  >
 
Post new topic   Reply to topic    µLua DS - Forum officiel | Official forum Forum Index -> English section -> Tutorials
Previous topic :: Next topic  
Author Message
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sat 18 Jul 2009 - 20:41    Post subject: Official Tutorials Translated! Reply with quote

Day 1: The Screen

The Material

The DS has two screens. The resolution of each of the screens is 256x192 pixels. Micro Lua uses the GPU 3D of the concole to draw 2D graphics with the advantage of removing many limits (more sprites on the screen, no map size limits, etc.). On the otherhand, the refresh rate is only 30fps instead  of 60fps. Therefore, each screen refreshes 30 times per second.

When you write a script in Micro Lua, you must specify the targeted screen with each graphic instruction. You can also use the two screens as one.

Some constants we will use to do this:
SCREEN_UP : top screen
SCREEN_DOWN: bottom screen
SCREEN_BOTH: both screens at the same time

You should never modify the value of these three two variables.


The Principle "Buckle"


All Micro Lua script contains a 'principal buckle'. In this 'buckle', you will cal ltwo functions: screen.startDrawing() and screen.stopDrawing(). It is between these two functions where we will place all of our drawing instructions. These two functions also make it possible to print
. You must put render() after you wish to print and/or draw. The two screens will therefore be automatically refreshed 30 times per second.

The code:


 
Code:



while true do

   -- Here, We Make Drawing Instructions
   render()

end 






Hello World


Let's now learn to write text on the screen (well, screens) with the traditional 'Hello World'!

 

 
Code:



while true do

   screen.print(SCREEN_UP, 16, 16, "Hello world !")
   render()

end 





Let's see how thet function screen.print functions.
The first parameter is the screen on which to draw (SCREEN_UP, SCREEN_DOWN, or SCREEN_BOTH). No explanation needed.
The two following parameters are the X-Coordinates and the Y-Coordinates telling the DS where to draw. The last parameter is a character string representing the text to be printed.
A final optional parameter exists, the color of the text. To create a color, you use the function Color.new(r, g, b). Where r, g, et b represent the quantity of red, green, and blue of the color.
For example, if you want to write the same thing in the color red, you write:

 
Code:




screen.print(SCREEN_UP, 16, 16, "Hello World!", Color.new(31, 0, 0)) 





If you don't set a color, the shown text will be white.


Use the two screens as one.

As it is written above, you can use the two screens as one. To do this, you use a constant (which is a variable) SCREEN_BOTH.

The text will be then shown on one of the two screens according to the value given.

example:
 
Code:

[del]



screen.print(SCREEN_BOTH, 16, 16, "Hello world !") Prints on the top screen
screen.print(SCREEN_BOTH, 16, 200, "Hello world !") Prints on the bottom screen
screen.print(SCREEN_BOTH, 16, 189, "Hello world !") Prints between the two screens
 


[/del]

By default, the space between the two screens is 0. You can modify that value by doing
screen.spaceBetweenScreens = new_value

There! You know how to print text on the screen! Let's continue to Day 2: The Controls.
_________________
Le français est fastoche Smile


Last edited by monkat on Sun 19 Jul 2009 - 15:02; edited 3 times in total
Back to top
AIM MSN
Publicité






PostPosted: Sat 18 Jul 2009 - 20:41    Post subject: Publicité

PublicitéSupprimer les publicités ?
Back to top
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sat 18 Jul 2009 - 20:43    Post subject: Official Tutorials Translated! Reply with quote

Day 2: The Controls

The Buttons

The DS has 12 buttons. Micro Lua makes it possible to locate the state of these buttons constantly (Pressed, Released, or Newly Pressed). To update the state of these buttons, you use the function Controls.read().
A structure of data makes it possible to recover the state of the buttons: the buttons structure. In this structure, there are three other structures:
held: to know if a button is pressed
released: to know if a button is released
newPress: to know if a button is newly pressed

Let us now see an example of code


 
Code:


while not Keys.held.Start do

Controls.read()

screen.print(SCREEN_UP, 0, 0, "Press START to quit")
render()

end
 



This code prints "Press START to quit" while the user has not pressed Start.

Thus, you understand that to know the state of a button, you use Keys.[STATE].[BUTTON]

Where [STATE] can have the values held, released, and newPress.
[BUTTON] can have the values A, B, X, Y, L, R, Start, Select, Up, Down, Left, and Right.

Respect the major things, as well as the minor things.


The Stylus

A structure of data makes knowing the state of the stylus available: the Stylus structure. The refreshing of this state is also done by calling the Controls.read() function.

The stylus structure allows us to know many things:
X: The X-Coordinate of the stylus on the bottom screen.
Y: The Y-Coordinate of the stylus on the bottom screen.
held: To know if the stylus is touching.
released: To know if the stylus is released.
newPress: To know if the stylus is newly pressed.
doubleClick: To know if the user makes a double click.
deltaX: Variation of the X-Coordinate while the stylus is moving on the screen.
deltaY: Variation of the Y-Coordinate while the stylus is moving on the screen.

Here is an example of code showing the usage of the stylus:


 
Code:


while not Keys.newPress.Start do

Controls.read()

if Stylus.doubleClick then
screen.switch()
end 


 screen.print(SCREEN_UP, 0, 0, "Stylet X : "..Stylus.X)
 screen.print(SCREEN_UP, 0, 8, "Stylet Y : "..Stylus.Y)
 screen.print(SCREEN_UP, 0, 16, "Stylet deltaX : "..Stylus.deltaX)
 screen.print(SCREEN_UP, 0, 24, "Stylet deltaY : "..Stylus.deltaY)
 render()
 
 end





This code waits for the user to press Start to stop. It also prints some information. When you make a double click, it switches the two screens (the function screen.switch()).

Now, let's move on to day 3: Images.
_________________
Le français est fastoche Smile


Last edited by monkat on Sun 19 Jul 2009 - 01:53; edited 1 time in total
Back to top
AIM MSN
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sat 18 Jul 2009 - 20:47    Post subject: Official Tutorials Translated! Reply with quote

Day 3: Images

Loading Memory


To use images, and to show them, you must first load them in memory. There are two types of memory on the DS:
-RAM (Random Access Memory) environ 4Mb
-VRAM (Video Memory) environ 600Kb if I don't say something silly
You can load images in each of the two memories. It is preferable to load a maximum of images in the VRAM to leave the RAM free for other objects such as audio files.

Micro Lua allows the usage of 3 types of images files: .png, .jpg (and .jpeg obviously), and .gif.

To load an file into memory:
my_image = Image.load("myfile.extension", destination)

Example:


 
Code:

img = Image.load("test.png", VRAM)
The destination can be RAM or VRAM. 




Showing The Images


To print an image on the screen, you use the function screen.blit.
Look at the official documentation for more information on this function.

Example of code:

 
Code:


img = Image.load("test.png", VRAM)

while true do

screen.blit(SCREEN_UP, 10, 10, img)
render()

end 



This code shows the image at 10, 10 on the top screen.

You can also show portions of an image. See the documentation at the examples for more details.

Let's move on now to day 4: Advanced Drawing Functions (NOT Currently Written)
_________________
Le français est fastoche Smile


Last edited by monkat on Sun 19 Jul 2009 - 01:54; edited 1 time in total
Back to top
AIM MSN
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sat 18 Jul 2009 - 20:48    Post subject: Official Tutorials Translated! Reply with quote

You're welcome Smile! This was the first thing that I have ever translated out of class :S...Please inform me of any errors! Also if you need any French / English / Spanish translations, I am always free! Just send me an instant message or an e-mail!!!
_________________
Le français est fastoche Smile


Back to top
AIM MSN
Reylak
Administrateur

Offline

Joined: 24 Nov 2008
Posts: 2,838
Localisation: Toulouse

PostPosted: Sat 18 Jul 2009 - 21:24    Post subject: Official Tutorials Translated! Reply with quote

Hum, it seems to be nicely translated, but finally useless : those tutorials are outdated since Microlua v3.0 prerelease.
Moreover, I and aurel2108 are working on a tuto for the "Site du Zer0" (search for Newbies Paradise if you want to see the English site), which is in validation by a moderator. When ours is validated, you'll be able to translate it.
_________________


Plein d'infos sur le SourceForge !


Back to top
Visit poster’s website MSN Skype
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sat 18 Jul 2009 - 21:39    Post subject: Official Tutorials Translated! Reply with quote

hehe Razz well that's always good xD I wish that the work wasn't wasted though xD Oh well
_________________
Le français est fastoche Smile


Back to top
AIM MSN
Reylak
Administrateur

Offline

Joined: 24 Nov 2008
Posts: 2,838
Localisation: Toulouse

PostPosted: Sat 18 Jul 2009 - 22:04    Post subject: Official Tutorials Translated! Reply with quote

It hasn't been wasted, because only the screen.startDrawing() / screen.stopDrawing() changed : you only use render() in place of screen.stopDrawing(), while screen.startDrawing() disappears. You should rectify this, I think this is the only modification that 3.0 did and which is presented in you translation.
_________________


Plein d'infos sur le SourceForge !


Back to top
Visit poster’s website MSN Skype
thermo_nono
Modérateur

Offline

Joined: 31 Dec 2008
Posts: 2,415
Localisation: La Géhenne

PostPosted: Sun 19 Jul 2009 - 01:19    Post subject: Official Tutorials Translated! Reply with quote

very good ! I probably will need your help to correct a documentation than I does for my library "Command-EZ".. 
Thx to propose your help : I have great difficultys in english.  Embarassed
_________________
“Qui reçoit une idée de moi reçoit de la connaissance sans diminuer la mienne, comme celui qui allume sa chandelle à la mienne reçoit la lumière sans me plonger dans l’obscurité.” - Thomas Jefferson


Back to top
Visit poster’s website MSN
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sun 19 Jul 2009 - 01:38    Post subject: Official Tutorials Translated! Reply with quote

I would be glad to, thermo Razz And I will fix the guides if I understand correctly...(Sorry, I am not very good at programming). Do you mean simply replace screen.stopDrawing() with render() and remove screen.startDrawing()?

----

Anyway, I edited them following that set of 'rules'. Thanks for the information Smile
_________________
Le français est fastoche Smile


Back to top
AIM MSN
thermo_nono
Modérateur

Offline

Joined: 31 Dec 2008
Posts: 2,415
Localisation: La Géhenne

PostPosted: Sun 19 Jul 2009 - 02:05    Post subject: Official Tutorials Translated! Reply with quote

yes, for the render() function you just have to replace "screen.stopDrawing()" by "render()" and remove "screen.startDrawing()". 
_________________
“Qui reçoit une idée de moi reçoit de la connaissance sans diminuer la mienne, comme celui qui allume sa chandelle à la mienne reçoit la lumière sans me plonger dans l’obscurité.” - Thomas Jefferson


Back to top
Visit poster’s website MSN
thermo_nono
Modérateur

Offline

Joined: 31 Dec 2008
Posts: 2,415
Localisation: La Géhenne

PostPosted: Sun 19 Jul 2009 - 02:47    Post subject: Official Tutorials Translated! Reply with quote

I've just uploaded the documentation of my library. If you have time to look at this, it could be  Okay .
here is my french doc :
http://sites.google.com/site/microlua/Home/projets/command-ez/Command-EZ(fr…
and here my try to traduct in english :
http://sites.google.com/site/microlua/Home/projets/command-ez/Command-EZ(en…
Embarassed

this two documents are written with MS-Word (.doc) if you can't read this format I'll try to convert in an other one.. just tell me..
thanx again for your work. 
to contact me, you can use my e-mail : arnaud.gasson@gmail.com
Post Scriptum : if you can make a spanish translation I'll be so happy.  Mr. Green
_________________
“Qui reçoit une idée de moi reçoit de la connaissance sans diminuer la mienne, comme celui qui allume sa chandelle à la mienne reçoit la lumière sans me plonger dans l’obscurité.” - Thomas Jefferson


Back to top
Visit poster’s website MSN
thermo_nono
Modérateur

Offline

Joined: 31 Dec 2008
Posts: 2,415
Localisation: La Géhenne

PostPosted: Sun 19 Jul 2009 - 13:59    Post subject: Official Tutorials Translated! Reply with quote

how.. I've just seen an other thing than has changed with µLua3 :
The instruction "SCREEN_BOTH" has been removed in µLua3. For the parameter on wich screen to draw, we can now just use SCREEN_UP and SCREEN_DOWN. 
(sorry for my poor english talkin, in french we said "je parle anglais comme une vache espagnole" ^^)
_________________
“Qui reçoit une idée de moi reçoit de la connaissance sans diminuer la mienne, comme celui qui allume sa chandelle à la mienne reçoit la lumière sans me plonger dans l’obscurité.” - Thomas Jefferson


Back to top
Visit poster’s website MSN
monkat


Offline

Joined: 18 Jul 2009
Posts: 13
Localisation: États-Unis

PostPosted: Sun 19 Jul 2009 - 15:03    Post subject: Official Tutorials Translated! Reply with quote

All fixed up Smile Thanks for all the help, guys! And haha, I love French idioms!!! They make no sense!!!
_________________
Le français est fastoche Smile


Back to top
AIM MSN
Reylak
Administrateur

Offline

Joined: 24 Nov 2008
Posts: 2,838
Localisation: Toulouse

PostPosted: Sun 19 Jul 2009 - 16:10    Post subject: Official Tutorials Translated! Reply with quote

Ho, I didn't see this BOTH_SCREEN in the tutos, but yes, it has disappeared since the 2.0 beta. You have good eyes thermo_nono :p
_________________


Plein d'infos sur le SourceForge !


Back to top
Visit poster’s website MSN Skype
sc1fi


Offline

Joined: 17 Jul 2009
Posts: 3

PostPosted: Wed 22 Jul 2009 - 18:31    Post subject: Official Tutorials Translated! Reply with quote

Thanks man for translating it! I haven't got very much problems to interpret french sentences (i'm romainian) but it's 1000times better to have it translated into english!^^

Back to top
Display posts from previous:   
Post new topic   Reply to topic    µLua DS - Forum officiel | Official forum Forum Index -> English section -> Tutorials All times are GMT + 1 Hour
Goto page: 1, 2  >
Page 1 of 2

 
Jump to:  

Index | Create a forum | Free support forum | Free forums directory | Report a violation | Cookies | Charte | Conditions générales d'utilisation
Powered by phpBB © 2001, 2005 phpBB Group