[Solved] Get computed width/height blocks not working in DnD

I am attempting to pick up on the width of the canvas by using the block “canvas computed width”. When i use this block, it returns 0. The way I am using it, I would expect to recieve a positive value because my canvas does in fact have width when I view it.

What i want to do is touch the canvas and save the proportionate position of the click and not the pixel value. This is the only way to scale the positions across devices seamlessly AFAIK.

2 Likes

You get 0 value because that canvas didn’t displayed yet.
Try to put something like this, between the creation of canvas and that retrieving its dimensions:
repeat while canvas1’s computed width = 0
wait 0.001

Thanks for the input. The canvas is always displayed before i try any action. This is unlikely as even with this setup I receive the 0 value.


^^^also doesnt work

1 Like

Ah, I read all wrong, I’m sorry. Thought you get zero as canva`s width and height.

You read right.

Specifically, when I ask to return the value of the computed Height or Width of Canvas1, the blocks return the value of 0 even though I have hard set the value at 375 pixels.

Like i

what loop are you referencing?

As i stated above, the canvas is always visible when this action happens. In fact, the canvas must to be visible since the action is a click on the canvas itself.

I appreciate you trying here but this is an odd bug. I have already reported it via intercom

1 Like

Can you place a dot in each corner of the canvas and get their coordinates?

Haven’t tried it myself but logically you can compute the size.

1 Like

No matter what I try, I can’t get the canvas’ computed width to be anything but zero. Not when screen opens, not when canvas loads, not when pointer is down, not when button is clicked…

Just confirming what you already know.

1 Like

This is a great idea, and will work to manually calculate sizes, but only if they can retrieve coordinates :thinking:

1 Like

this would also imply that someone needs to place the points first, right? I’l try this out iinstead of waiting on an answer

i guess a better question is: If I set the canvas to 375 pixels in the editor, will ALL screen sizes respect this width? anyone wanna sample this with me? I am on an iphone 11 and would need to see the results on something like an android

my answer is here


and it’s no. if i set this to be 375, the app will try to apply these sizes to different screen sizes, which is nice but doesnt help when i cant get the value of the canvas easily

it’s actuallly a yes i think. no matter the screen size i test them on, the app always interpret the distance as 375 pixels.

the idea is that i want to make a marker on an image in my app, then view it on any other device and make sure that the marker falls in the same spot without modifying the original image in the first place.

1 Like

I placed a canvas in the screen and added a Sprite Type. I used the new sprite type to place one in the top left and one in the bottom right. I then get the position of the sprite which will aid in calculating the size.

Of course you will choose a sprite image that is less obvious that what I used but I needed to see them in the screen.

[Edit]

After giving it some thoughts, you don’t need the sprite in the top left corner because it is (0,0) so the only sprite you will need is the bottom-right corner which is approx. (290, 440)

so oddly enough, when i published this as a webapp on a it registers the same number of pixels when viewed on my computer as on my iphone. (maybe due to dpi) but its also the same as when viewed on the live app. in 2 of those 3 places the image is the same size but on my computer the webapp image is bigger than 375 pixels for sure but only registers as such. so, in my mind, the React Native engine is (in the background) stretching pixels which isn’t a thing but more likely they are using a CSS Scale feature to up/down the size thereby saving pixel density… in my mind that’s whats happening anyway. perhaps someone like @Steven could comment on the system behind sizing up and down between screen sizes and what that does to pixel locations and pixel coordinates on bigger/smaller screens when everything is set in fixed pixel sizes using the new editor.

1 Like

Hi @jared - thanks for reporting this, and everyone else for helping out. I’ve shared with our engineering team and we will investigate further soon!

2 Likes

@jared In the stage drawer, get any of the blocks that return a value. Then change the property to be “Height” or “Width”. This will give you the size of the canvas that is used for the sprite coordinates.

I don’t know why the Height/Width aren’t available in the drawer by default. We’ll fix this in a future release.

4 Likes

Thank you @paulmw, I can confirm those blocks do, in fact, work to produce the desired result!

Here was my final (simple) test case

The use case here, btw, is so that I can recreate this same image/dropped points combo on any device! I’ll send this off to Firebase and recall it later on a computer in a webapp!

2 Likes