Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing Basic Game Controls in HarmonyOS

Tech Nov 8 23

This example demonstrates how to implement basic game controls using H5, leveraging the button component in ArkUI to showcase the ability to inject and execute JavaScript in a WebView, as well as communication between native applications and H5 pages.

The H5 game page used in this example is provided by https://yangyunhe369.github.io/h5-game-blockBreaker/.

Preview

Instructions:

  1. Connect your device to a hotspot to access the internet.
  2. Open the app and control the game using the buttons on the interface.

Project Structure

entry/src/main/ets/
|---entryability
|   |---EntryAbility.ts                // Dialog component
|---model
|   |---Logger.ts                      // Logging utility
|---pages
|   |---Index.ets                      // Home page

Implementation Details

This example uses a module that enables basic game control through buttons. It leverages the WebviewController methods to manage the behavior of the Web component, along with JavaScript injection and execution capabilities.

Permissions Required

Internet access permission: ohos.permission.INTERNET

Dependencies

No dependencies are required.

Constraints and Limitations

  1. This example runs only on standard systems.
  2. Its compatible with API version 9 SDK, version 3.2.11.9.
  3. It requires DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023) for compilation and execution.

Download

To download the project separately, run the following commands:

git init
git config core.sparsecheckout true
echo code/BasicFeature/Telephony/RunJsInWeb/ > .git/info/sparse-checkout
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
git pull origin master

To further enhance your understanding of HarmonyOS development, we have prepared a complete set of the latest HarmonyOS NEXT learning resources. Click the link below to get the full version:

HarmonyOS Video Tutorial: Syntax of ArkTS, TypeScript, ArkUI, etc.

HarmonyOS Ecosystem Application Development White Paper V2.0 PDF

HarmonyOS Development Guide

Getting Started

For more information about HarmonyOS development, refer to: https://docs.qq.com/doc/DZVVBYlhuRkZQZlB3

Tags: HarmonyOS

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.