Microsoft MakeCode

Little bug

let mySprite = sprites.create(img. . . . . . . . . . . c c c c c 6 6 6 6 6 . . . . . . . . . . . . . . . . . . . c c c 4 4 4 4 4 4 4 4 4 4 6 6 6 . . . . . . . . . . . . . . c c 4 4 4 4 4 4 4 4 4 b b 4 4 4 4 4 6 6 . . . . . . . . . . . c b 4 4 4 4 b b 4 4 4 4 b 5 b 4 4 4 4 4 4 b . . . . . . . . . e b 4 4 4 4 b 5 b 4 4 4 4 4 b 4 4 4 4 4 4 4 4 b . . . . . . . e b b 4 4 4 4 4 b 4 4 4 4 4 4 4 4 4 4 b 4 4 4 4 4 6 . . . . . e b 6 b b 4 4 4 4 4 4 4 4 4 b b 4 4 4 b 5 b 4 4 4 4 4 6 . . . . e 6 b b 5 b 4 4 4 4 4 4 4 4 b 5 b 4 4 4 b 4 4 b b 4 4 e . . . e 6 6 b 4 b 4 4 4 4 4 4 4 4 4 4 b 4 4 4 4 4 4 4 b 5 b 4 4 e . . e 6 b b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 b b 4 4 e . e b 6 6 b 4 4 4 4 4 b b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 b e e b 6 6 b b 4 4 4 b 5 b 4 4 4 4 4 4 4 4 b b 4 4 4 4 4 4 4 4 b e f b 6 6 6 b 4 4 4 b b 4 4 4 4 4 4 4 4 4 b 5 b 4 4 4 4 4 4 4 b f f c b 6 6 6 b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 b b 4 4 4 4 4 4 b c f . f b b 6 6 6 6 b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 b f . . e f b b 6 6 6 6 6 b b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 b f e . . 8 6 f c b b 6 6 6 6 6 b b b 4 4 4 4 4 4 4 4 4 4 4 b c c 6 8 8 8 7 7 2 e f f c b b b b b b b b b b b b b b b b c f c 2 2 7 7 8 8 7 7 2 2 2 2 2 c c c c c c c c c c c c c c c c 2 2 2 2 6 6 7 8 f 8 6 6 6 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 6 6 8 6 f f e f 8 6 6 6 7 7 7 6 6 6 6 7 7 7 7 7 7 6 6 6 7 7 7 7 f f f e f f b f f 8 7 7 7 6 8 f 8 6 7 7 7 7 7 7 6 6 6 7 7 6 f f f f f b f f b e f f e e f f f e f f 7 7 6 6 6 8 8 e f f e e e e f e b 6 f f 6 b f f f e f f e e e e e e e e e e e e e f e e e e e b b 6 e f 6 6 d d f f f f f e e e f f e f f e e e e e f f e e d b 4 6 e . c 6 6 d d d 4 e f f f f f f e e e e e f f f f 4 d d b 4 6 e . . f c 6 b 4 d d d d d d d d d d d d d d d d d d d b 4 4 4 e e . . . f f 6 b b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 e e . . . . . . f f b b b b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 e e . . . . . . . . . . f f e b b b b b b 4 4 4 4 4 4 4 4 e e e . . . . . . . . . . . . . . . f f f f f f f c c c c c e e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ., SpriteKind.Player)
let velx = 40
let vely = 60
mySprite.vx = velx
mySprite.vy = vely
mySprite.setFlag(SpriteFlag.StayInScreen, false)
forever(function () {
if (mySprite.x >= 110) {
vely = mySprite.vy * -1
velx = mySprite.vx * 1
mySprite.vx = velx
mySprite.vy = vely
}
})

What im trying to do is change the sprites direction after it hits the bottom of the screen (trying to recreate it without using the bounce on wall thingy) but it bugs out, the sprite starts to shake, any help? thanks

Your sprite gets over the edge, you flip the direction, it flies a tiny little bit but not enough to cross the edge, and you flip it again.

Only flip vy if it’s positive.

I understand what you mean, but i still dont get how i could fix it, could your provide me with an example? thank you

Focus on the following line:

if (mySprite.x >= 110) {

Change it to a compound conditional (i.e. use &&) and only change values if mySprite.x is in the turnaround zone and mySprite.vx is positive.

You also have

velx = mySprite.vx * 1

I’m thinking you have a typo there.

1 Like

Thank you!, just what i needed.