Help with pixel art end math issue's

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

6 Likes

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

2 Likes

hey @richard why those this not work
image
but this dose
image
image

2 Likes

Can you show me the function definition?

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

4 Likes

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

2 Likes

@Blobbey nope!

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

4 Likes

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

2 Likes

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
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

2 Likes

@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?

3 Likes

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

3 Likes

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 )

3 Likes

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

hopefully that’s enough to get you started!

4 Likes

i see.
thank you @richard

3 Likes

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

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 ?

3 Likes

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,

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; 
6 Likes

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

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

i was sepose to put

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

does /= not work in makecode ?

4 Likes

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

5 Likes

i see, thank you

3 Likes

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

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?

3 Likes

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:


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

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

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