How to convert a matrix into cloned sprites

I'm trying to make a 2048 game in snap and I want to be able to convert a 2D matrix into cloned sprites quickly

I'm very familiar with clones so i'm doing it the lazy hardcoded way which gets the job done, but it's way to slow to be useful:


Does anyone know how I can convert the matrix into sprites without hardcoding all the locations and preferable in a faster way. Right now this code takes ~half a second to work and I want the data to refresh much faster.

Each clone should know its position. In fact, why should it ever move at all? Tell it its position when it's created, and then you can use BROADCAST when you want to change its costume. Right?

You'd need the clones to move in order to create a moving animation.


To get an item in a grid is actually pretty easy.

untitled script pic (8)

The first value is the column, and the second is the row.

If you don't want to hard code the positions, then it's very similar.

63 is the width of a tile, -90, 23 is the bottom right top left corner of the grid. 4 is the grid size.

Top left, if you're using Snap!'s coordinates.

I thought we were rewriting that WHEN I START AS A CLONE script. It has the starting positions, nothing about movement. So I stand by using a BROADCAST to send each clone (we can do that now!) its starting coordinates, instead of all those IFs.

By the way, you can store positions as vectors and GO TO them by dropping them on the pulldown menu.

You're right, I didn't test where the coordinates are in snap before I posted, I did test the actual math to make sure it works correctly.

Huh. You've been around long enough that I'm surprised that that isn't an instinct for you! Three "that"s in one sentence! We use the same Cartesian coordinates everyone outside the world of computer programming uses. I guess it's confusing if you're also programming in other systems that have the Y axis upside down and the origin at the top left, but for those systems there are no negative coordinates.

I know the coordinate system. I sometimes get mixed up with left and right. I don't know how I thought it was bottom. I guess it's because I've been modding snap, and the snap ide coordinates (source code) are flipped on the y axis, so 0,0 is in the top right left (wow, I'm really getting mixed up with those), which means, negative values would be above the screen. That's the same with pretty much every gui programming, html and css, python tkinter, and svg. I've been focused on those a lot more than snap.

Yeah, and it's all because whoever made the first TV decided that the scanning should start in top left.

I don't really want to get the clones to move since that would be more effort than I want to spend on this project
I've edited my code it doesn't use a huge if test:

https:// drive .google.com /file/d/19-ao1ONSTefc1BvYVwhQNhlrBQkKdP2_/view?usp=share_link
(I'm not able to send a link or image so just delete the spaces I added to get this to not register as a link)

But it still uses one if statement for the costume stuff and I'd really like to remove it somehow. I want clone# mod 4 to return 4 if it is divisible, and the correct value otherwise. Is there any way to do that faster?

yes
untitled script pic

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.