# Help with pixel art end math issue's

**URL:** <https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809>\
**Category:** Arcade\
**Tags:** game, graphics-and-math, make, extension, art\
**Created:** [March 27, 2023, 11:15pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809 "2023-03-27T23:15:28Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [April 27, 2023, 9:26pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/24 "2023-04-27T21:26:18Z")

</div>

nevermind im good thank you for your help @richard i couldn’t of done it without you  
i am now standing proud of my first extention

> **[ImageEditor Extention](https://arcade.makecode.com/19490-56850-09555-42854)**
>
> Fait avec ❤️ dans Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [April 28, 2023, 4:21pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/25 "2023-04-28T16:21:36Z")

</div>

hey @richard is there a way for a “image” type to already have an image inside?  
ho en i might no be able to Watch the whole streem today

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 1, 2023, 4:55pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/26 "2023-05-01T16:55:43Z")

</div>

hey @richard why those this not work  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b8d646bb1df4c3ef6fe6e6f0fa7e53598287d2e9.png)  
but this dose  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e3b3be0faf30cb1d36e976e4bdf1af42cb3d618c.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c94f1bdc1a2f626deb1f0dc3de8ab8464cb2c91e.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e8dc8e535a25908fb31e06324acea72f754cc8a5.png)

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 1, 2023, 11:40pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/27 "2023-05-01T23:40:21Z")

</div>

Can you show me the function definition?

Also instead of `%max` use `$max`. The percent syntax is deprecated because it’s buggy!

---

<div class="post-metadata">

**Author:** ![Blobbey](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/blobbey/32/20831_2.png) [@Blobbey](https://forum.makecode.com/u/Blobbey)\
**Post date:** [May 2, 2023, 4:25pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/28 "2023-05-02T16:25:28Z")

</div>

@richard, I saw this and wanted to ask: if the `%max` is deprecated, does that mean it’s also deprecated for `//% block`?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 2, 2023, 4:27pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/29 "2023-05-02T16:27:05Z")

</div>

@Blobbey nope!

The only place that % is deprecated is where you are referencing the parameters of your blocks. Use $ instead.

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 3, 2023, 6:44pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/30 "2023-05-03T18:44:51Z")

</div>

i dont know what you mean by the function definition but i think it means

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2355f11a25cb913b11a16d6c483b79ff6b629252.png)

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 15, 2023, 4:20pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/31 "2023-05-15T16:20:26Z")

</div>

hey @richard im making a game with a spitial kind of movement and i want to make it a extention but how do i make it work.  
well here is a example  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/aa736a742661f04eccc699d356842238d24faf2e.png)  
i only need to activate this block once and i can move whenever i want and dont need to reactivate it. how do i do that

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 16, 2023, 4:19pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/32 "2023-05-16T16:19:10Z")

</div>

@YuHayate I’m not sure I understand what you’re trying to do, can you give me some more details? What specifically is the extension trying to do?

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 17, 2023, 1:22am UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/33 "2023-05-17T01:22:05Z")

</div>

well im making a extention that turns images to a isometric world in 3d but i nee to be able to move in that dimension so i cant just use the normal move (mySprite) vx 100 vy 100  
here is the [Project](https://makecode.com/_7djb7pDbyHJ6)

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 17, 2023, 4:48pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/34 "2023-05-17T16:48:07Z")

</div>

sorry for the variables odd names

> **how to decode**
>
> (here’s how to decode. copy everything after the “ID” and convert from hexadecimal to text. (ID + Hex name.) its that easy )

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 17, 2023, 11:29pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/35 "2023-05-17T23:29:20Z")

</div>

ah, i think i understand! you want to make your own controller.moveSprite that moves on an isometric coordinate system instead of the usual up/down/left/right.

Well here’s some sample non-isometric code for you: [https://arcade.makecode.com/S39885-15306-76114-61239](https://arcade.makecode.com/S39885-15306-76114-61239)

hopefully that’s enough to get you started!

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 18, 2023, 5:34pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/36 "2023-05-18T17:34:26Z")

</div>

i see.  
thank you @richard

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 19, 2023, 4:37pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/37 "2023-05-19T16:37:24Z")

</div>

when the vertical and horizontal buttons a activated the speed is twice as fast

```auto
function moveSprite(sprite: Sprite, vx: number, vy: number) {
        const tileRatio = Math.sqrt(3) / 2 * 32 / 111; // Tile ratio

        control.runInParallel(() => {
            while (!(sprite.flags & sprites.Flag.Destroyed) && TilemapList[IsometricPlayerZ]) {
                let dx = 0;
                let dy = 0;

                if (controller.up.isPressed()) {
                    dy--;
                }
                if (controller.down.isPressed()) {
                    dy++;
                }
                if (controller.left.isPressed()) {
                    dx--;
                }
                if (controller.right.isPressed()) {
                    dx++;
                }

                // Reduce the magnitude of velocity vectors when two directions are pressed
                let magnitude = (Math.abs(dx) + Math.abs(dy));
                if (magnitude > 1) {
                    vx / magnitude;
                    vy / magnitude;
                }

                let isoDx = (((dx - dy) * vx) * tileRatio) / tileRatio; // Calculate isometric x distance
                let isoDy = (((dx + dy) * vy) * tileRatio / 2) / tileRatio; // Calculate isometric y distance

                // Set the sprite's velocity to the converted isometric velocity
                sprite.vx = isoDx;
                sprite.vy = isoDy;

                pause(1);
            }
        });
    }

```

it just doesn’t work do you have any advice ?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 19, 2023, 4:44pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/38 "2023-05-19T16:44:10Z")

</div>

> [@YuHayate](#):
>
> ```auto
> let magnitude = (Math.abs(dx) + Math.abs(dy));
> if (magnitude > 1) {
> vx / magnitude;
> vy / magnitude;
> }
> 
> ```

This part right here isn’t actually doing anything in this code. You need to assign the results of the division to a variable, and then use that. For example,

```typescript
let magnitude = (Math.abs(dx) + Math.abs(dy));
let scaledVx = vx;
let scaledVy = vy;

if (magnitude > 1) {
    scaledVx = vx / magnitude;
    scaledVy = vy / magnitude;
}

let isoDx = (((dx - dy) * scaledVx) * tileRatio) / tileRatio; // Calculate isometric x distance
let isoDy = (((dx + dy) * scaledVy) * tileRatio / 2) / tileRatio; 

```

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 19, 2023, 7:59pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/39 "2023-05-19T19:59:54Z")

</div>

i see thank you  
also i made a mistake while remaking the code  
insted of

```auto
 let magnitude = (Math.abs(dx) + Math.abs(dy));
                if (magnitude > 1) {
                    vx / magnitude;
                    vy / magnitude;
                }

```

i was sepose to put

```auto
 let magnitude = (Math.abs(dx) + Math.abs(dy));
                if (magnitude > 1) {
                    vx /= magnitude;
                    vy /= magnitude;
                }

```

does `/=` not work in makecode ?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 19, 2023, 10:46pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/40 "2023-05-19T22:46:10Z")

</div>

it does work, but you don’t want to use it here. vx and vy are parameters of the function and won’t be reset after each iteration of the loop. in other words, they’ll keep getting smaller and smaller every frame until your sprite isn’t moving at all

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 21, 2023, 1:43am UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/41 "2023-05-21T01:43:41Z")

</div>

i see, thank you

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [May 24, 2023, 10:40pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/42 "2023-05-24T22:40:13Z")

</div>

hey @richard in exthetions i see “sprite[name-sprite-somthing]” what does it do

```auto
let IsometricPlayerX[sprite] = IsometricPlayerX[sprite] + dx
let IsometricPlayerY[sprite] = IsometricPlayerY[sprite] + dy
let IsometricPlayerZ[sprite] = IsometricPlayerZ[sprite] + dz

```

this is what i think it is “its a way to attach data to a variable”  
and i dont know how to use it. can you help me?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [May 24, 2023, 10:51pm UTC](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809/43 "2023-05-24T22:51:33Z")

</div>

the square brackets are used to access properties or indices in JavaScript. You should only ever put strings or numbers in the square brackets. Other types (like Sprites) will cause errors.

For example:

```auto

let myObject: any = {
    someProperty: 27,
    someOtherProperty: "hello",
    "a string property": true
}

console.log(myObject["someProperty"]) // prints 27
console.log(myObject["someOtherProperty"]) // prints hello
console.log(myObject["a string property"]) // prints true

// invalid properties return undefined
console.log(myObject["property that doesn't exist"]) // prints undefined
console.log(myObject[34]) // prints undefined

let myArray = [12,34,1,17];

console.log(myArray[0]) // prints 12
console.log(myArray[3]) // prints 17

// out of bound indices return undefined
console.log(myArray[-1]) // prints undefined
console.log(myArray[100]) // prints undefined

```

Now what you might have seen is that sprites have a property called `data` that you can use to store things. It’s an object, so you can use the square brackets to store things using strings

```auto
let mySprite = sprites.create(img`1`, SpriteKind.Player);

mySprite.data["my custom property name"] = // whatever you want!

```

[Previous page](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809.md?page=1)

[Next page](https://forum.makecode.com/t/help-with-pixel-art-end-math-issues/18809.md?page=3)
