Ok, yesterday I worked on a version that uses the background and renders 54x20 pixels (1080 pixels), instead of 320, which the old one had. This is the highest resolution in which the simulator would render over 30fps (using my rendering method, which is probably somewhat inefficient.)
It won’t run on my end
Sorry, I think that link broke. Here’s one that works.
(I’m uploading from mobile cuz I’m on a trip so there might not be an image)
Pls explain how this whole thing works I really wanna know but my tiny brain cannot understand the code
One more advice, the fill rectangle block is veeeery sloooow.
Try using the set ( ) color at x ( ) y ( ) with a higher resolution, it may run better.
As far as I know, the fastest way to draw is to use scene.createRenderable
combined with Image.setRows
. That’s what I use in Space Rocks 3D.
Here’s an older discussion about the topic: Is it possible to write directly to screen (pixels) on the Arcade?
scene.createRenderable
takes a function as its second argument, that function gets called each time the screen content is refreshed on updates. The called function gets an Image
as its first argument which is a reference to the screen buffer, you can modify that image to draw directly onto the screen.
The image.getRows
and image.setRows
methods copy pixels from the screen into a byte buffer and back.
Something like this (untested):
const buf = Buffer.create(120)
const zLayer = 0
scene.createRenderable(zLayer, (target: Image, camera: scene.Camera) => {
for (let x = 0; x < 160; +=x) {
// Read the current screen content for modification
image.getRows(x, buf)
// Now "buf" contains a color value for the current pixel row
// (it's actually a vertical column onscreen) where it can be modified.
buf[12] = 15
// Write the modified pixels back to the screen.
image.setRows(x, buf)
}
})
Yeah, but you can’t do that in blocks
I made it render 1600 pixels (20x80) and it looks good(30 fps on pc)(thanks @Nome_muito_criativo ). if I would try for 20x160 the framerate is horrible. (sorry @kwx I don’t know Javascript so I don’t know how to implement your method)
also, anyone have any idea how to make the actual casting of the rays be faster, because that’s my main problem. I’m using a 1x1 sprite and detecting what tile is in that sprite’s position for each pixel and I think there might be a more efficient method. If anyone knows or has any ideas please let me know because I want to get to full pixel density (1x1 pixels instead of 2x1 pixels).
That’s the goal.
I’m working on collidable pipes
Instead of using sprites you could use X and Y variables, just increment them instead of setting the sprite’s position, then you can get the tile under them with the
(tilemap cols ( ) rows ( ))
block.
The problem is, I’m working with angles and there’s no “detect tile (angle) (distance) from (mysprite)”
This is called “polar coordinates”, to convert to x and y (cartesian coordinates) you just set
x = distance * cos (angle)
y = distance * sin (angle)
Considering an angle of 0 to be on the right
NOTE: trigonometry in MakeCode uses radians not degrees
Thanks! I haven’t taken trigonometry yet, so I never learned how cos and sin worked. I’ll get working on the code!
The rendering is warped and movement doesn’t work correctly, but thanks @Nome_muito_criativo , but do you have any ideas on how to fix movement and warping?
am back!!!
Welcome back, nice to see you again ^-^