Enhancing speed with Cocoon.js and Three.js

Recently, I created a simple 3D game using box2Dweb to handle physics and three.js for rendering. It's a basic side-scrolling game and now I'm looking to get it running smoothly on iOS. To achieve this, I've opted to package the game using cocoon.js, which supports WEBGL on iOS devices.

The main issue I'm facing is performance. While the game runs at a decent 50 frames per second on a desktop, it crawls at a mere 3 frames per second on an iPhone 5.

In an attempt to boost performance, I stripped down the game by removing textures, shaders, skybox, and rendering only parts of the level visible to the camera. This helped achieve a 25% increase in performance, bringing it up to 4FPS.

I took a look at the demos available in the iOS launcher app, and they all run smoothly without any hiccups.

At this point, the only other optimization idea I have is to minify the JS code, but I doubt it will significantly improve performance.

In my current setup, I'm using the Accelerated Canvas/WebGL feature in the launcher app and have also experimented with the canvas+ option, but the issue persists. My three.js version is revision 67, and I'm utilizing the webGL renderer as follows:

this.renderer = new THREE.WebGLRenderer

If anyone has suggestions on how to enhance the performance of three.js with cocoon.js, I would greatly appreciate it!

Answer №1

After some optimization, I have successfully enhanced the frame rate to approximately 25 fps, a significant enhancement.

To achieve this, I eliminated all shadows, not only those cast by objects, but also those from all light sources and the renderer:

object3d.castShadow = false;

light.castShadow = false;

renderer.shadowMapEnabled = false;

An excessive number of light sources was identified as the primary issue. By reducing them to just one, there was a notable improvement in the frame rate.

Additionally, removing the fog resulted in a few extra frames per second.

Lastly, I compressed the JavaScript code, which appeared to provide a modest enhancement in performance.

Answer №2

It's fantastic to see that you have successfully resolved your issue.

You may not be familiar with the concept of "back-face culling", which is commonly used to enhance performance in Games.

(Any polygons that are not visible are not rendered) For a more detailed explanation, you can refer to this wiki link: http://en.wikipedia.org/wiki/Back-face_culling

I would also suggest checking out this excellent 3D Graphics course, which focuses on Three.js:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve data from an HTML form and utilize it to search a JSON array for a specific value

If I have a Json File structured like this: {"403": [ { "403-01-01": "219,00" }, { "403-01-02": "180,00" } ], "404": [ { "404-01-01": "26,00" }, {"403-01-02": " ...

Troubleshooting Issues with AngularJS HTTP.get Requests

I'm currently working on a simple AngularJS application that is supposed to extract data from a .json file. While my code doesn't show any errors upon running it, it fails to retrieve the JSON values as expected. I have a feeling that I may be ov ...

What is the best way to show an SVG icon in React without having to make an HTTP request for the file?

A special requirement for a react application is to display icons in certain parts of the application while offline. The use of inline svg is particularly fitting for this purpose. import React from 'react'; // Utilizing inline svg to showcase i ...

The <form> element is giving me headaches in my JavaScript code

Trying to troubleshoot why my HTML pages render twice when I add a form with JavaScript. It seems like the page displays once with the script and again without it. Below is the basic HTML code: <form action="test.php" method="post"> <div class=" ...

I'm completely baffled as to why the client console is unable to locate my JS file

I have a question that may seem basic, so please bear with me! I'm having trouble adding a js file to an html page and it seems to be related to the file path. In my HTML page, I have this code to link the file: <script src="../src/utils/mapbo ...

How can we utilize CSS floats to achieve maximum widths?

I currently have 5 divs that I need to structure in a specific way: Each div must have a minimum size of 100px The parent container should display as many divs as possible on the first row, with any remaining divs wrapping to new rows if necessary If the ...

How can constants from components be defined in multiple ways when imported? (specifically in React)

Although I have a good understanding of React and Javascript, I struggle to articulate my question effectively. I will provide examples in the hopes that someone with more expertise in the field can assist me. For instance, when using import { useRef, use ...

The console is failing to display the value associated with the key

In this snippet of JSON code, the key "pants" is nested under the "children" key for MALE when gender is selected as male. However, if the selected gender is female, then "pants" becomes a children key of FEMALE. var data = { "gender": "male", "myFi ...

Exploring Angular $resource with a playful twist

Is there a recommended method for mocking the $resource object? I've looked online, but all my attempts ended with KARMA testing. It's not what I'm looking for. I'm thinking of creating a fake object so that I can easily switch betwee ...

Turn off HTML5 Audio

There are 4 <audio> elements on a webpage. The client has asked for them to be available sequentially. Meaning, the first audio should play, then the rest should remain disabled until the first one finishes, and so on. In addition, they want the au ...

Using Jquery to drag and drop items into a specific target zone

Check out my Jquery code: $(".list").draggable({helper: 'clone', cursor: 'hand'}); $(".drop1").droppable({ accept: '.list', hoverClass: 'dropareahover', drop: function(ev, ui){ var targetId = $(this) ...

Obtaining text from a select list using JQuery instead of retrieving the value

How can I retrieve the value from a select list using jQuery, as it seems to be returning the text within the options instead? Below is my simple code snippet: <select id="myselect"> <option selected="selected">All</option> <op ...

The JQqplot graph is failing to display correctly following an ajaxpost operation

When drawing a chart in two different scenarios, the first scenario is during the onload event and the second one is after the successful completion of an ajax post. The same code is being called in both scenarios. During the onload function, the chart l ...

What is the best way to eliminate the content of an element using javascript/typescript?

The progress bar I'm working with looks like this: <progress class="progress is-small" value="20" max="100">20%</progress> My goal is to use javascript to remove value="20", resulting in: <progre ...

On the second attempt to call setState within the componentDidMount method, it is not functioning as expected

As a newcomer, I am delving into the creation of a memory game. The main objective is to fetch data from an API and filter it to only include items with image links. On level one of the game, the task is to display three random images from the fetched data ...

Having trouble getting datatables.net to function properly with JavaScript

I've been experimenting with datatables from http://datatables.net/ Attempting to make it work using javascript, but I'm facing issues. Even when following the example provided on the website, it still shows a blank page. Does anyone have any su ...

Selecting from a variety of options presented as an array of objects

I am currently working on a component that allows users to select roles: https://i.stack.imgur.com/bnb9Y.png export const MultipleSelectChip = ({ options, label, error, onRolesUpdate, }: Props) => { const theme = useTheme(); const [selected ...

JavaScript: Utilize MooTools to extract a string containing a specific class and then pass it through a parent function

I am facing a major issue and struggling to find a solution for it. My problem involves returning values, mostly strings, that I can utilize in various contexts. For instance, I need to verify whether something is 0 or 1 in an if/else statement, or insert ...

Is it possible for a font to exclude the space character?

I'm currently developing a font detection library that must be extremely compact in size, perfect for direct inclusion on every page of a website. I've managed to shrink it down quite a bit already (compressed to 417 bytes). Take a look at it on ...

Using `popWin()` in conjunction with `echo php` in Javascript

How can I create a JavaScript popup window inside an echo line? I have tried the following code but the popup window does not work: echo '<td> <a href="javascript:popWin(edit.php?id='.$row[id].')">Edit</a></td>&apos ...