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)
Curious to know why a sprite cannot be inserted into this scene? https://makecode.com/_dKkPsCRg2ERJ
@frank_schmidt the camera coords are way lower, try using relative to camera
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 ^-^
Iāve been working on this for a hours and I found some wiki articles, but I just canāt seem to get the rendering right. Am I missing something in the calculation of the angles?
I donāt know, I havenāt actually looked very far into the code, but it seems correct.
@Nome_muito_criativo are you finished with the mode 7 project or is it abandoned?