Examples

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
If it would help, I'm happy to work through the mojo2 examples that ship with CX, correcting any errors, removing redundant code and improving comments if necessary. It'll be useful for me as a learning exercise and hopefully benefit others who are new to the project.

Here's my edit of BitmapFont.cxs. The comments could be formatted better IMHO, what do you think?
 

Attachments

  • BitmapFont.cxs
    2.9 KB · Views: 152

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
Personally, I'd only comment those lines that relate to the feature being illustrated as per this version.

EDIT: Also remove superfluous things, like the cross-hair in the original example.
 

Attachments

  • BitmapFontv2.cxs
    982 bytes · Views: 196

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
How would you like the edited files submitted? I think I can just about figure out github pull requests if necessary!
 

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
@MikeHart Can you check I've made a pull request properly for the first example, I'm not very well versed with github?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
The pull request is visible. May I ask why you removed all the comments that explain things? And who the original author is?
 

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
The pull request is visible. May I ask why you removed all the comments that explain things? And who the original author is?

I thought it would be better to just comment on the lines that were directly related to the example, in this case the parts concerned with loading and drawing the text. Otherwise every example will have the same comments over and over :D

Most of the mojo 2 examples don't include the author's name etc so I though having them with a simple common header explanation would be best.

I've re-worked 'Bouncy Aliens', it didn't look right when run as every sprite was being scaled by a random amount each frame and it was full of bits of test code that had no relevance. I've headed it up as:

Code:
' Cerberus X - Bouncy Aliens example
'
' Shows how to use a stack, handle suspend and resume events, use pre-processor directives and achieve simple animation.

Otherwise, I'm not sure exactly what it's supposed to be an example of!
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
Otherwise every example will have the same comments over and over
Agreed.

Btw. while
Code:
canvas = New Canvas()

works with the parenthesis,

Code:
canvas = New Canvas

is better imho. It isn't a function/method, its an object.

Otherwise, I'm not sure exactly what it's supposed to be an example of!
One of M.S.'s test scripts I guess.
 

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
Agreed.

Btw. while
Code:
canvas = New Canvas()

works with the parenthesis,

Code:
canvas = New Canvas

is better imho. It isn't a function/method, its an object.

Well the docs say Canvas is a class with a New constructor just like classes in most other languages, it's just habit I suppose. The same optional parenthesis thing seems to apply all over the place. SetDeviceWindow for example is a function and shown with parentheses in the docs but can be called without! I was trying to be consistent in that regard :D
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
Ahh ok. Command without parameters need the parenthesis in Strict mode, commands with parameters not. The joy of the CX transpiler!
 

Paul59

New member
CX Code Contributor
Joined
Dec 13, 2018
Messages
375
Haha, better stick with parens :p

Also, can you change the case of the Bitmap Font example folder and files on Github as it doesn't match the others which are all in lower case.
 
Top Bottom