Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:02:07+00:00 2026-05-16T04:02:07+00:00

I am working on a game that has AI logic, movement, etc and drawing.

  • 0

I am working on a game that has AI logic, movement, etc and drawing. Does it make sense to calculate moving and AI logic using Web Workers? But how do I do that — because the workers need to know so much about the main thread like the positions of certain objects for collisions, amount of bullets, etc. It feels like impossible because the worker is completely separate from the main thread with no access what so ever. I do know that there a postMessage() system, but that feels so … umm, painful?

For example, I have a rifleman object that represents a rifleman with a sprite, position, health, etc. I want him to patrol. So, how do I do that patrolling code on a worker? It would need pretty much the whole access to that object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:02:08+00:00Added an answer on May 16, 2026 at 4:02 am

    I think it does make sense to use WebWorkers for a game, but yeah, it will mean you will have to keep a game state object which can be converted to valid JSON which you can pass to webworkers. On the brightside, you can also put a lot of intrinsic data inside those webworkers as well.

    var gameState = {
       sprites: {
          {
             type: 'rifleman',  // damage, accuracy, speed etc set inside appropriate webworker.
             owner: 'playerA', 
             x: 100,
             y: 100,
             z: 0,
             level: 1, // used to fetch modifiers to dmg, acc, speed etc.
    
          },
          {
             // each sprite it's own state obj.
          }
       }
    }
    

    then you set up a webworker for patrolling and possible events (you can call other webworkers inside a webworker as well and process patrol events)

    var patrolWorker = new WebWorker('patrolWorker');
    patrolWorker.onmessage = function(e){
       render(e.data); // your render function, can ALSO be a webworker if you like ;)
    }
    patrolWorker.postMessage(gameState.sprites);
    

    It must become clear by now, that using WebWorkers is actually very much an architectural decision, if you want to use them, it will involve a lot of refactoring. Without the refactoring, I doubt it’s useful for you at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web application (ASP.NET) game that would consist of a
I'm working on a game that has simple pixel-art sprites. Since I'm planning to
Alright so here is my issue. I'm working a game engine that will eventually
I'm working on a game (C#) that uses a Robocode-like programming model: participants inherit
I'm working on an iPhone game that takes place on the ocean surface. Can
I'm working on a game (using Ruby) and planning to have it available in
I am working on a Facebook game which is developed using Zend framework. Right
I am working on a Facebook game which is developed using Zend framework. Right
Working on a project that has a website and a Facebook page. They both
I'm writing a game for iOS. It has a game map, and I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.