Problem in Canvas

Does anyone know why this problem happens? The size of the Canvas is 64x64, and the Tiles are 16x16.
41 Replies
bigmistqke
bigmistqke3w ago
we need a bit more information before we can help you: what is the expected behavior? what is the code?
SleepPolar
SleepPolarOP3w ago
Sure, no problem. I removed a bit of code so it could be understood better.
No description
No description
SleepPolar
SleepPolarOP3w ago
As for the expected behavior, it is that the straight line is straight, it does not have that small slip
No description
bigmistqke
bigmistqke3w ago
mm 🤔 no idea what could cause that. if you can make a minimal reproduction in the playground i can mess around with it too
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
SleepPolar
SleepPolarOP3w ago
Oh, but I'm not using solid to do that
bigmistqke
bigmistqke3w ago
ye doesn't matter you can just grab a reference to a canvas and then do the canvas stuff on it just handy to have it in the playground, for quick sketching
SleepPolar
SleepPolarOP3w ago
@bigmistqke here it is
SleepPolar
SleepPolarOP3w ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
SleepPolar
SleepPolarOP3w ago
No description
bigmistqke
bigmistqke3w ago
i cannot seem to reproduce it which browser are you using?
SleepPolar
SleepPolarOP3w ago
Google Chrome
bigmistqke
bigmistqke3w ago
windows/linux/mac?
SleepPolar
SleepPolarOP3w ago
Windows Can I send you the code file and try it on your computer?
bigmistqke
bigmistqke3w ago
if you see it in the playground and i don't see it i don't think the code files will help i m on mac i don't think it's anything to do with your code it's more a weird canvas-bug i would check different (non-chrome) browser firefox p.ex
SleepPolar
SleepPolarOP3w ago
ok, i would check in Microsoft edge
bigmistqke
bigmistqke3w ago
that's also chrome
SleepPolar
SleepPolarOP3w ago
oh xd
bigmistqke
bigmistqke3w ago
🙂 they r everywhere mb it's the fact that the canvas is width="64" height="64" some glitch with
image-rendering: pixelated;
image-rendering: crisp-edges;
image-rendering: pixelated;
image-rendering: crisp-edges;
you could check if you have the bug as well if you do not do width="64" height="64" and manually rescale those values to match the window's width/height
SleepPolar
SleepPolarOP3w ago
what do you mean 🤔
bigmistqke
bigmistqke3w ago
you use width="64" height="64" in combination with image-rendering: pixelated; image-rendering: crisp-edges; to make a responsive grid i think this might cause the pixel glitch so i propose to make a variant where you don't rely on width="64" height="64" and image-rendering: pixelated; image-rendering: crisp-edges; to check if you still have that bug
SleepPolar
SleepPolarOP3w ago
I cannot remove the image-rendering since it is pixelart. But if I remove the height and width, it would look like this, I don't see that error happening, maybe because it is very small, or because the error no longer happens. But the bad thing is that it would no longer be a 64x64, and the squares would be smaller and wouldn't look like a 16x16 in a 64x64
No description
bigmistqke
bigmistqke3w ago
gotcha weird bug!
SleepPolar
SleepPolarOP3w ago
Yes, I just asked stack overflow to see if anyone knows why it happens and how to solve it. Either they insult me, or they help me. :yah: I'll let you know if I solve it.
bigmistqke
bigmistqke3w ago
MDN Web Docs
CanvasRenderingContext2D: imageSmoothingEnabled property - Web APIs...
The imageSmoothingEnabled property of the CanvasRenderingContext2D interface, part of the Canvas API, determines whether scaled images are smoothed (true, default) or not (false). On getting the imageSmoothingEnabled property, the last value it was set to is returned.
bigmistqke
bigmistqke3w ago
this could be of interest too lol stackoverflow s so brutal
SleepPolar
SleepPolarOP3w ago
I asked 4 questions there and all 3 of them insulted me lmao, and in one they helped me I tried it before 😔 Broo... Not even 10 minutes have passed and they already gave me a dislike on stackoverflow 😭
bigmistqke
bigmistqke3w ago
being able to ask the right question is a skill it can be hard in the beginning
bigmistqke
bigmistqke3w ago
Stack Overflow
Why is there a one pixel offset in my canvas?
I was drawing some 16x16 images on my canvas. I made the canvas size 64x64. And I made it look bigger with CSS. The reason why I enlarged it with CSS instead of modifying the size of the canvas. It...
SleepPolar
SleepPolarOP3w ago
yes Any recommendations for modifying the post? They only made me upset, but they didn't tell me why.
bigmistqke
bigmistqke3w ago
ye, i kind of understand the downvote 😄 people have to do a lot of effort to be able to understand your problem
SleepPolar
SleepPolarOP3w ago
I just modified it, is it understandable a little better?
bigmistqke
bigmistqke3w ago
it's a lot of clutter you should narrow the problem down to the essence and ask for this
SleepPolar
SleepPolarOP3w ago
Something like this? I’m drawing 16x16 pixel images on a 64x64 canvas and using CSS to scale them. However, one corner of the image is misaligned by a pixel. Can someone help me figure out why this happens and how to fix it?
bigmistqke
bigmistqke3w ago
1. clearly formulate the bug 2. give the context (css with image-rendering: pixelated and image-rendering: crisp-edges), which browsers does this happen? which os? 3. give a minimal reproduction so that people can try it out on their device. it's a bit the same as what i asked here + code is always better then text but also don't drop huge amount of code, try to make it as small as possible minimal reproductions are really the key
SleepPolar
SleepPolarOP3w ago
I'm going to do that. thanks for the recommendation 👍
bigmistqke
bigmistqke3w ago
you are welcome! good luck 🙂
SleepPolar
SleepPolarOP3w ago
Perfect, I already modified it, it has very little code and can be run to replicate the error, and I got straight to the point. They closed the post though, so I'll have to wait a while until they review it. 👍
bigmistqke
bigmistqke3w ago
it's definitely an improvement 👍 https://stackoverflow.com/help/minimal-reproducible-example funny, this is pretty much what i was saying too you could probably clean it up even more
SleepPolar
SleepPolarOP2w ago
I forgot to tell you, a chill guy responded to me, he said that scaling it with width and height sometimes causes fractional scaling, and that's why there are misaligned pixels. And it is solved simply by using "scale" in the transform. 😃
bigmistqke
bigmistqke2w ago
glad you figured it out! so, you mean with doing transform: scale(...) in the css?
SleepPolar
SleepPolarOP2w ago
yep
Want results from more Discord servers?
Add your server