جواب «Catch the Star» چالش 3 از جلسهی 8
سؤال
ستاره (star) وسط صحنه است. با salam.tap کاری کن هر جای صحنه که لمس شد، ستاره همانجا برود: star.x برابر x لمس و star.y برابر y لمس.
راهنما
بیرون از حلقه: salam.tap(function (x, y) { star.x = x; star.y = y; });
یک جواب درست
<script>
const ctx = salam.canvas(360, 480);
const starImg = salam.image("star");
const star = { x: 180, y: 240 };
salam.tap(function (x, y) {
star.x = x;
star.y = y;
});
salam.loop(function (dt) {
ctx.fillStyle = "#1b1440";
ctx.fillRect(0, 0, 360, 480);
ctx.drawImage(starImg, star.x - 20, star.y - 20, 40, 40);
});
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن