Using Artificial Intelligence to create a 2D game Part 1

OSCAR CID
5 min readMay 21, 2023

--

Introduction

In the world of game development, creating visually appealing and unique assets is a crucial aspect of capturing players’ attention and immersing them in the game’s world. Traditional methods of designing sprites and textures for 2D games can be time-consuming and require significant artistic skills. However, thanks to the advancements in artificial intelligence (AI), developers now have access to powerful tools that can generate high-quality designs automatically.

One such tool is Leonardo.ai, a cutting-edge AI platform that offers a range of features tailored specifically for game developers using Unity.

Requeriments

  • Unity 2022.2 or above
  • Photoshop or any other graphic editing program
  • URP or HDRP

Leonardo.AI

Leonardo.ai

Leonardo.ai offers an intuitive and user-friendly interface specifically designed for game developers. Its rich set of features includes:

  • Sprite and Texture Generation: The platform can generate a wide range of sprites, including characters, objects, and environmental elements. It can also create high-quality textures for backgrounds, tiles, and other visual components.
  • Artistic Style Transfer: Developers can experiment with various artistic styles and apply them to their generated assets, adding uniqueness and diversity to their game’s visuals.
  • Real-time Previews: Leonardo.ai provides real-time previews of the generated sprites and textures, allowing developers to visualize and assess the assets before integrating them into their projects.
  • Customization Options: The platform offers customization options, enabling developers to tweak parameters such as color schemes, shapes, and sizes to achieve the desired visual results.

Before starting to use Leonardo AI, we must register for free on their website:

  • Click on the top button that says Get Early Access and enter our email.
  • Once we have received the confirmation email, we can access the app using the Launch App button.
  • A pop-up window will appear, click where it says Yes, I’m whitelisted.

Generating assets by AI

Once we have access to the application, to start creating AI-generated images, on the page that appears, we will go to User Tools -> AI Image generation.

For this article, we are going to follow the following steps, as we could get lost among the many options they offer. But don’t be afraid to experiment with them once you become familiar.

  • We select from the dropdown menu the model we are going to use, Leonardo Diffusion and Leonardo Style.
  • We’ll choose a prompt. A prompt is the initial text or description you provide to instruct the model on what you want to create. It sets the context and helps guide the generation process.
  • Finally, we click on Generate to see the results in a short period of time. Each generated image costs something called tokens, which is specified both in terms of cost and availability based on the plan you want to use.

Prompts

I have used the following prompts:

forest tree multiple separated variations background rayman legends , simple, cute, full colour, flat colour,no outline
rocks multiple separated variations background rayman legends , simple, cute, full colour, flat colour,no outline
2d grass asset, rayman legends style , horizontal , plain background
seamless dark brown soil with rocks texture pattern, rayman legends style
little boy character,clenched fists, multiple poses and expressions,children’s book illustration style , simple, cute, 10 years old boy, full colour, short brown air, flat colour,no outline

Editing in Photoshop

Basically, in Photoshop, we will use two tools called Object Selection Tool and Quick Selection Tool.

Object Selection Tool: The Object Selection Tool is designed to automatically detect and select objects within an image. It uses AI-powered technology to identify and create selections around objects based on their edges. This tool saves time and effort by quickly selecting objects without the need for manual selection.

Quick Selection Tool: The Quick Selection Tool is used to make fast and rough selections of specific areas in an image. It works by automatically detecting the edges of objects based on color and texture similarities. By simply brushing over the desired area, the tool intelligently selects and expands the selection to cover similar pixels.

When we have an object selected using the Object Selection Tool and it is missing some parts to be recognized, we will use the Quick Selection Tool by clicking on those parts. If we want to remove certain parts, we will use alt + click on those areas.

For the character, we will follow the same procedure for each body part: head, upper body, bottom, left arm, right arm, right foot, and left foot. After completing the editing, we will export the file in PSB format.

End of part 1

In the next article, we will use these AI-generated assets with Unity and create basic controls to move the character.

If you enjoyed this article and would like to support my work, consider buying me a coffee on BuyMeACoffee. Your support helps me keep creating free, high-quality conten

--

--