I have an example code for gliding my sprite across the screen to a destination coordinate. Seems simple but when I use it in my code, it say that glide is not a function. Not sure how to fix this…I just want that simple motion towards a specific x and y value.
If you share your code, we may be able to help you troubleshoot.
Let us know.
Mike
I am trying to have a sprite “glide” or move to a specific x,y coordinate. I found example code but the game lab doesn’t run it. Code below…
countking = 0;
var start = false;
var background = createSprite(200, 200);
background.setAnimation(“background”);
background.scale = .35;
var GameOver = createSprite(200, 200);
GameOver.visible = false;
GameOver.setAnimation(“background_underwater_17_1”);
var barb = createSprite(194, 365);
barb.setAnimation(“barb”);
barb.scale = .07;
barb.rotation = 180;
barb.setCollider(“circle”, 80, 0, 60);
var hook = createSprite(200, 590);
hook.setAnimation(“hook”);
var king = createSprite(0, 200);
king.setAnimation(“ChinookRT”);
king.scale = .4;
king.velocityX = 4;
king.setCollider(“circle”, 30, 0, 25);
var king2 = createSprite(0, 100);
king2.setAnimation(“Chinook2RT”);
king2.scale = .3;
king2.velocityX = 6;
king2.setCollider(“circle”, 0, 0, 25);
function draw() {
if (start) {
hook_movement();
king_movement();
if (barb.isTouching(king)) {
playSound(“https://audio.code.org/winpoint1.mp3”, false);
king.x = 360;
king.y = 320;
king.velocityX = 0;
hook.x = 200;
barb.x = 194;
hook.y = 590;
barb.y = 365;
countking = countking + 1;
}
if (barb.isTouching(king2)) {
playSound("https://audio.code.org/winpoint1.mp3", false);
king2.x = 360;
king2.y = 340;
king2.velocityX = 0;
hook.x = 200;
barb.x = 194;
hook.y = 570;
barb.y = 365;
countking = countking + 1;
}
if (countking == 2) {
start = false;
GameOver.visible = true;
king.visible = false;
king2.visible = false;
barb.visible = false;
king2.visible = false;
hook.visible = false;
}
drawSprites();
} else {
textFont(“Arial”);
textSize(24);
if (keyDown(“s”)) {
start = true;
}
}
}
function hook_movement() {
if (hook.y < 200) {
hook.x = 200;
barb.x = 194;
hook.y = 590;
barb.y = 365;
}
if (hook.y > 579) {
barb.visible = true;
hook.velocityY = 0;
barb.velocityY = 0;
}
if (keyDown(“right”)) {
hook.x = hook.x + 3;
barb.x = barb.x + 3;
}
if (keyDown(“left”)) {
hook.x = hook.x + -3;
barb.x = barb.x + -3;
}
if (keyDown(“space”)) {
hook.y = hook.y - 15;
barb.y = barb.y - 15;
}
if (keyWentUp(“space”)) {
barb.visible = false;
hook.velocityY = 2;
barb.velocityY = 2;
}
}
function king_movement() {
if (king.x > 450) {
king.setAnimation(“ChinookLT”);
king.velocityX = -4;
king.y = randomNumber(60, 300);
}
if (king.x < -20) {
king.setAnimation(“ChinookRT”);
king.velocityX = 8;
king.y = randomNumber(60, 300);
}
if (king2.x > 450) {
king2.setAnimation(“Chinook2LT”);
king2.velocityX = -4;
king2.y = randomNumber(60, 300);
}
if (king2.x < -25) {
king2.setAnimation(“Chinook2RT”);
king2.velocityX = 15;
king2.y = randomNumber(60, 300);
}
}