Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Pixelbox

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

PICO8's memcpy equilavent

A topic by Fred Bednarski created Apr 12, 2020 Views: 591 Replies: 4
Viewing posts 1 to 4

One of the awesome aspects of Pico8 was being able to use memcpy to copy and paste parts of the screen to make cool effects.

I know that pixelbox does not map memory like fantasy consoles, but it would be cool if there was an function to copy and paste parts of the canvas in a similar manner.

(+1)

The screen canvas is a Texture instance that is accessible from the $screen global variable. It's possible to draw a Texture in another Texture (and even to itself). There's not yet any function to draw just a part of a texture, but this should be possible to implement. 

Good to know that you can read the texture. It would be awesome if there was a function that would let you grab a rect from that texture. 

If it doesn't fit on your roadmap, I am pretty sure you can do it with js as is (or with a use of library). Which makes me think - can you add your own libraries? 

(4 edits)

Until something like this is supported by Pixelbox, you could drop down to the native html canvas and do something like this:
https://www.w3schools.com/tags/canvas_getimagedata.asp
I typically avoid w3schools examples, but this pretty succinctly describes what you're trying to do. You can use document.querySelector('canvas') to find the canvas that Pixelbox is drawing to, and use the getImageData()/putImageData() methods on the context from the canvas.

actually the global $screen Texture stores the canvas as $screen.tilesheet and the context2d as $screen.ctx, so you should be able to use $screen.ctx.getImageData()/putImageData().

(+1)

You should be able to npm install pretty much anything you want (that works in browser land), then import/require it.