Adventures of an Entrepreneur
  • Creating a Mobile Apps/Games Company

Image in Corona:  width/height, contentWidth/contentHeight, x/yScale and stroke (border)

1/5/2013

0 Comments

 
Our first game is a puzzle one, so we had to deal a lot with image manipulation. In this post I would like to share some basic knowledge about dealing with image in Corona and also some details that could save you some time in the future.

First, create a empty text file and save it as main.lua.

Now let show a image, my dolphin.jpg file, in the screen. We can do that by writing the following code inside the main.lua:
local img = display.newImage( "dolphin.jpg")
In the code above we displayed the image (dolpin.jpg) in the screen and created the variable img that will handle the image. Our screen will look like below:
Picture
Using the image properties (accessible by the variable name, in our case, img) we can specify the image position, increase/decrease its height or width and modify other properties. You can see the common image properties here.

Now lets change the image position just a little away from the margin.
img:setReferencePoint(display.TopLeftReferencePoint)
img.x = 50
img.y = 100
In the first line of the code above, we just specify what point of the image (e.g: Center of the image, top-left corner,...) Corona must use to position the image. In our case, we specified that we want the top-left corner of the image to be at the (x,y) = (50, 100). 

Just remember that top-left corner of the screen is the (0,0) coordinate and as you move to the right the x-axis increases. As you move down you increase the y-axis.

Our updated screen is like below:
Picture
Lets say that we want to reduce the width of the image by half. We can do that by writing the following code:  
img.yScale = 0.5
The code above reduces the original y-dimension (image height, that in our case is 276 pixels) of the image by a factor of 0.5. Just be careful that yScale (or the xScale) is based on the original image dimensions (height or width). I.e, if we write the code above again in the file, nothing will change in the screen. If I would like to reduce the size by half again, I would have to set the yScale factor to 0.25. 

The xScale and yScale reduce the respective image dimension by the factor specified, leaving unmodified the original image dimension (height, width). 

So, now our screen is as below.
Picture
Since the image height is maintained unmodified, if we would like to get the image height that we see in the image (i.e, half of the original), we could use the properties contentHeight (img.contentHeight) instead of the height property (img.height). I will show a summary in the end of the post that will clarify that difference.

We could have changed the image height by setting the property height of the image (img.height). In that case, just make sure that you reset yScale to 1 (or the final image would still be affected by the scale factor).

Now lets learn how to create a border (stroke) in an image. To do that, we just have to write the following code:
img:setStrokeColor(255,255,255)
img.strokeWidth= 5
In the first line of the code above, we define what color (in RBG) the border will have. In the next line, we define the border width.  You need to specify the border width or the border will not show in the screen.

Lets see how our image (without the yScale = 0.5) would be with the code above.
Picture
Now you already know how to show an image in the screen, how to set its position, reduce its dimensions and also set a border to it.

To summarize all that we saw above, I created the screen below in which I show the same image with different xScale and yScale. I printed in the screen the main properties of the image so you can see how the xScale / yScale affect them.
Picture
I ask you to pay attention to the border of the images. Did you notice that when you use xScale or yScale properties the border width is also modified?

So, be careful if you want to include a border to an image that has a xScale or yScale different from 1. If the image is reduced and you want to include a border width = 1, you probably have to set it with a width value more than 1 (since the border width will be reduced).
0 Comments

Where should I start to learn Game Development

12/4/2012

0 Comments

 
A question that people usually ask me is: "Where should I start to learn game development?". Based on that, I made a list of basic skills that I think every coder needs to know, together with a link where you can find that information. They are focused on the Corona SDK, cross-development platform that we are using at our company.

1) Basic Corona concepts
This section contains the basic concepts of Corona programming, as variable, functions, logic operators etc. If you are a coder, you will be able to read that section really fast. If you aren't, I recommend you to read carefully to really understand the concept, since it will be the base for all your programming.

Link: http://developer.coronalabs.com/content/introduction

2) Display Objects and Groups in Corona:
This section explains how objects are displayed in the screen and their properties (position, color,...).

Link: http://developer.coronalabs.com/content/display-objects

3) Events and Listeners:
Events are what the name says: Events. When you touch your device screen, you make an Event of touching. When you rotate your device, you made an Event of rotation. So, you can think of Event as predetermined actions that occurs with the device. 

Listeners are functions that will take care of your event. As example, if you want the device to erase all data in the screen when the user shake the device, you need to have a listener that will be "listening" all events that are happening in the device and when it listens the event Shake, it will start running some codes that will erase the screen.

Link: http://developer.coronalabs.com/content/application-programming-guide-event-handling

4) Physics module:
In the item #2 you will have learned how to display objects in the screen, but in gaming, you usually needs not only to display the object but enable it to interact with other objects. That interaction is made thru the Physics module.

http://developer.coronalabs.com/content/game-edition-box2d-physics-engine

5) Animations / Sprite Sheets:
Depending on which type of game you are developing, you will need to display images that have motion, like a player running or a bird flying. To make animations you will use Sprite sheets.

A Sprite sheet is a image file that contains several static images of your object, that if played sequentially it would make your object move. It is the basic technique of animation that we learned when we were children that we made several drawings with minor differences and then we passed thru the drawings very quickly and it would appear to be moving. 

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

6) StoryBoard
StoryBoard is a API that helps you to manage your application screens. It will allow you to have more control and facilitates the process of screen transitions. Although you can make the screen transitions without it, I highly recommend you to use it due to the facilitates of screen management that it will bring to you as your code gets bigger.

Link: http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/

If you have any questions or doubts that these items, feel free to ask me thru the comments section.

See you.
0 Comments

Soon review about 2 tools for Corona

11/6/2012

1 Comment

 
Andres Loew gentily gave me free licences to review two of his products. The products are:
  • PhysicsEditor: tool that helps you create perfect shapes for physics interaction
  • TexturePacker: tool that helps you create sprite sheets for your game

I will try the products and post a complete review here in this blog. In the meantime, I suggest you to check the programs' website because they appear to be very useful (and they work not only with Corona, but also almost cross-development platform).
1 Comment

Programming, Debug and IDE for Corona

10/22/2012

0 Comments

 
In one of my previous post I mentioned that we selected Corona as our Cross Development Platform. The programming language that you use with Corona is called Lua. You just write your game code in Lua and Corona will compile it to run at iOS or Android. The question is: Where do I write my Lua code? The answer is simple: in any text file. That's right, you just need to open a text file and start coding there. When you are done, just save with your file as main.lua and run it with Corona. Since it is simple text file, you can write it using your Windows notepad. In fact, we had done half of our first game using notepad. But, you may want to use some software specially made to code development. That kind of software, called IDE, provides very useful resources that can improve your efficiency when programming, as auto-complete, auto-highlight variables/functions with colors and, in my view one of the main resources, a debug. For those who do not know what is a debug, I will explain now.

When you write a code to do some operations and to show you a result (like a code to sum 2 numbers) you expected it to do exactly what you want, correct? If the program runs and show you an unexpected result, or even simple does not show any result, it has some kind of problem. That problem is called in the computing world as a bug. So, when you try to find the bug to fix it, we say that you are debugging the software. When you want to debug, you usually monitor the program running line by line and see if it is running as you expected. To follow the program running, you could just print in the screen every result that program calculated in order to identify where the problem is (i.e, in which line of the code). But using a IDE with a debug is much easier. Such IDEs allow you to run the code and make it stop at a determined line so you can see the variables values at that time. Depending of the bug, the IDE will actually stop automatically in the line that has an error. So, a debug is very useful to help fix your code problems.

As I said, we started our first game using a notepad, but when we reached a point that we needed to fix some bugs, we looked for a IDE with a debug and I will share with you what I found and what we are using now.

IDEs for Corona
  • Corona Project Management (CPM): it comes together with Corona and you can use it for free during 30-day trial period. But that IDEs does not provides debug (at least today. It appears that the debug functionally will come in future versions).

  • Lua Glider IDE (formely know as Cider): it is a paid IDE (you can use it also for free during a trial period) made specially for Corona and has a debug mode as also several useful resources (like integration with version control softwares). We chose that IDE to use.

  • Corona.Complete: Another IDE made specifically for Corona. Its has a debug mode and you can try it for free. I particularly did not like it due to its different paid versions.

  • IntelliJ IDE: It is a generic IDE and you can configure it to use with Lua/Corona. It is free and is a very robust software. Although it has debug, I read in several blog people saying that it was not working very well. Also, you need a third party application to run it with Corona. You can find a tutorial on how to configure that IDE with Lua/Corona here.


If you are starting with Corona and does not want to use a IDE now, I recommend using one of the softwares below. They are a kind of a enhanced version of the notepad. Although it has not a debug, it has some cool features as auto-indentation, auto-highlight with colors,... They are free.

  • For Windows: Notepad++
  • For MAC: TextWrangler 


That its for today. See you.
  
0 Comments

Development Plataforms (Part II)

9/30/2012

0 Comments

 
Hi.

I already wrote about some development platforms, but for those who continue with doubt about which one to choose, I recommend you to read this site.

That post contains a extensive comparison of Corona, Gideros, Love and Moai. In addition, you can see the code of the famous "Hello World" using that engines.

If you already used one of those platforms (and even the other that I already discussed - Unity and Ethanon),  give us your opinion using the comment area.

See you.
0 Comments

Learning the basics

8/28/2012

0 Comments

 
Hello.

In my last post I said that, for your fist game, I recommend you to develop a simple one like throwing darts at balloons. To help you achieve that, I list below some video tutorial that shows how to create these simple games. These videos are based on Corona platform, the one that I chose to use. They are also a great opportunity for you to get familiar with all the resources that Corona provides.
Tutorial: Make a game in 8 minutes (good tutorial to learn the basics - event handlers, physics,..)
Tutorial: Make a game in 8 minutes - Part 2 
Ballon Burst Game - Part 1 (great tutorial to learn how to make a simple game) by Dr. Rafael Hernandez
Ballon Burst Game - Part 2 by Dr. Rafael Hernandez 
Ballon Burst Game - Part 3 by Dr. Rafael Hernandez 
I hope you enjoy the videos. You can find a lot more on youtube. See you.
0 Comments

Development Platforms

8/1/2012

0 Comments

 
In my last technical post, I talked about the programming languages required for each mobile system. I said that if you want to develop a game (or app) for iOS system, you would need to program using Objetive-C and if you target Andoid, you would need to use Java. If you are ok with that, you just need to download the respective IDE (Integrated development environment) and start programming. Find below some IDEs that you can use:
  • For iOS development: you need to use the X-Code IDE
  • For Android development: There are several available. One of them is called Eclipse.

If you want to know more about the IDEs avaliable, just google "IDE for Android" for example.

For those who do not want to write two codes for the same game/app, there is an alternative called Development Platform (or also called Cross-Development Platforms). These platforms allow you to write a single code and the platform makes the necessary work to build you game/app in the desired final system (iOS, Android, Windows Phone,...). There are a lot of these platforms and if you want a list of them, just google it. Find below some of platforms that I investigated when I was choosing the one that I would use.

Unity
Pros: Great platform for 3d development; One time license fee
Cons: Required extra effort to configure for 2d development

Corona
Pros: Very easy to use and t program; Focus on 2d games
Cons: License fee is annual

Ethanon
Pros: Very robust platform for heavy image games; Free
Cons: Not easy to program (require similar C++ programming language knowledge)

I chose Corona to develop my games. A recent survey published by Game Developer magazine with mobile game developers found that 53.1% use Unity, 39.8% use a custom engine, 17.7% use Cocos2D, 5.3% use Marmalade and 5.3% use Corona (the number don't sum up 100% because one developer can use more than one platform). You can find the article about the survey here.

Any question or if you want to add some info, feel free to post a comment.

0 Comments
Forward>>

    Author

    This blog it not updated anymore.  

    Archives

    February 2015
    June 2014
    May 2014
    April 2014
    March 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    July 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013
    December 2012
    November 2012
    October 2012
    September 2012
    August 2012
    July 2012

    Categories

    All
    Data
    Event
    Fun
    Games
    Key Success Factors
    Management
    Marketing
    Mobile
    Monetization
    Movies
    Startup
    Statistics
    Technical
    Tutorial
    Videos

Powered by Create your own unique website with customizable templates.