On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Pixelbox

Create 2D games in JavaScript, made easier · By Cedric Stoquer

Wait before execute game loop

A topic by Froggygoloso created Dec 13, 2021 Views: 215 Replies: 1
Viewing posts 1 to 2

HI! I need to be sure to enter the game loop with all my animations ready, what i would like to do is:

- Fetch from an external JSON some information on how to recolor some images (i see that it's correclty read in the debugger)

- Load some local images and recolor them with canvas, using the information from the JSON (i managed to recolor them without JSON, trying with a pre-determined color). These Images cannot be saved locally, but are needed runtime.

- Start the game loop, draw the map and the recolored images.

At the moment i enter the game loop without the recolored images ready, is there a way to check this? or delay the
exports.update = function ? Thanks for the attention, i must admit i'm fairly new to js too but i managed thanks to your guides

Hi Froggygoloso,

If you're still struggling with this, this might be worth a try - apologies if you've already tried something like this!

When I'm making games with PixelBox I usually move the actual update logic outside of the "exports.update = function so the main.js ends up looking a bit like this:

It's probably not strictly speaking the best way of doing this, but you should be able to make sure that your recolouring code runs before you start drawing things to the canvas. It does depend a bit on how exactly you're trying to do this at the moment, but this should let you effectively delay things.

Hope this helps - if not I might be able to offer some more suggestions if you're comfortable with sharing some code here, but no worries if not!