Sunday, 30 March 2025

Setup Your First KAPLAY Application by referring the kaplay js in html file.

Step 1: Initialize a New Project. Open your terminal and run below commands.

mkdir my-game
cd my-game
npm init -y

This creates a new project directory and initializes it with a default package.json.

 

Step 2: Install a Local HTTP Server

Install a lightweight development server, such as http-server:

 

Step 3: Create Project Structure

Create the following structure in your project folder.

my-game/
│
├── index.html
├── scripts/
│   └── main.js
├── package.json
└── .gitignore

Update index.html and main.js with below code.

 

main.js

import kaplay from "https://unpkg.com/kaplay@3001/dist/kaplay.mjs";

// Start kaplay
kaplay();

 

index.html

<html>
  <head>
    <title>Hello World</title>
  </head>

  <body>
    <script src="./scripts/main.js" type="module"></script>
  </body>
</html>

Add start script to package.json file.

 

"start": "http-server ."

 

package.json

{
  "name": "my-game",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "http-server ."
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "http-server": "^14.1.1"
  }
}

Step 4: Start the Application.

Run the Development Server.

npm run start

Open your browser and navigate to the URL provided by http-server (usually http://localhost:8080).

 


 

You can download the Application from this link.


Previous                                                    Next                                                    Home

No comments:

Post a Comment