0

I'm trying to make a Slot Game with canvas, but I can't place fruit images. Can you help me

Thank you in advance for your help

enter image description here

I tried making a Slot Game with canvas on discord

The gambling bot I will build will exist to entertain people virtually. Just like OwO

   run: async(client, message, args, embed) => {
  const canvas = createCanvas(600, 400);
  const ctx = canvas.getContext('2d');
  const background = await loadImage('https://cdn.discordapp.com/attachments/945327700514578473/1136943445336928287/background.png');
  ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  ctx.font = 'bold 70px Cambria Math';
  ctx.fillStyle = '#ff0000';

  const cilek = await loadImage('https://cdn.discordapp.com/attachments/1134127945733115975/1137194865042665553/cilek.png')
  const elma = await loadImage('https://cdn.discordapp.com/attachments/1134127945733115975/1137194865323692053/elma.png')
  const karpuz = await loadImage('https://cdn.discordapp.com/attachments/1134127945733115975/1137194865646637136/karpuz.png')
  const kiraz = await loadImage('https://cdn.discordapp.com/attachments/1134127945733115975/1137194866011557908/kiraz.png')
  const seftali = await loadImage('https://cdn.discordapp.com/attachments/1134127945733115975/1137194866393223219/seftali.png')
  ctx.font = 'bold 30px Cambria Math';


  let array = [Object(cilek, elma, kiraz, seftali, karpuz)];
  let random = array[Math.floor(Math.random() * array.length)];
  let random2 = array[Math.floor(Math.random() * array.length)];
  let random3 = array[Math.floor(Math.random() * array.length)];
  let random4 = array[Math.floor(Math.random() * array.length)];
  let random5 = array[Math.floor(Math.random() * array.length)];
  let random6 = array[Math.floor(Math.random() * array.length)];
  let random7 = array[Math.floor(Math.random() * array.length)];
  let random8 = array[Math.floor(Math.random() * array.length)];
  let random9 = array[Math.floor(Math.random() * array.length)];
  message.channel.send({ content: `${random} ${random2} ${random3}` })

  if ( random == random2 && random2 == random3 ) {
    // tam kazanma
    } else if ( random == random2 || random2 == random3 || random == random3) {
    // yarı kazanma
    } else {
    // tüm para kayıp
    }
  
    let satir1 = random + random2 + random3
    let satir2 = random4 + random5 + random6
    let satir3 = random7 + random8 + random9
  
    if ( random4 == random5 && random5 == random6 ) {
    // tam kazanma
    } else if ( random4 == random5 || random5 == random6 || random4 == random6) {
    // yarı kazanma
    } else {
    // tüm para kayıp
    }
  
    if ( random7 == random8 && random8 == random9 ) {
      // tam kazanma
      } else if ( random7 == random8 || random8 == random9 || random7 == random9) {
      // yarı kazanma
      } else {
      // tüm para kayıp
      }
    

  // Slot satır 1
  ctx.fillText(random, 20,120);
  ctx.fillText(random2, 170,120);
  ctx.fillText(random3, 320,120);
  ctx.fillText(random4, 20,240);
  ctx.fillText(random5, 170,240);
  ctx.fillText(random6, 320,240);
  ctx.fillText(random7, 20,360);
  ctx.fillText(random8, 170,360);
  ctx.fillText(random9, 320,360);

What do I need to fix?

mrtomblue
  • 118
  • 1
  • 11
Kadirhan
  • 1
  • 3
  • If you use `fillText` and pass in an image, JS will turn the `Image` element into a string using `toString()`, which results in `[Object object]` - what you are looking for is `ctx.drawImage`. This is expected behaviour. (Also, I'm assuming that `loadImage` returns an `Image` element ("``") – somethinghere Aug 07 '23 at 14:14

0 Answers0