Hello all,
I am new here and playing with Pixi.js using latest build but learning with old tutorials and examples.
My question is I am working on a Board Game: Jackpot game
Problem: I want to generate 3 Random Sprite images on canvas but how to do that. I tried but it's not working, how to pass random fruit image into sprite and display it on canvas.
Thanks in Advance.
PIXI.loader
.add("images/48.png", "images/49.png", "images/50.png", "images/52.png")
.load(setup);
function setup() {
var randomFruits = ["images/48.png", "images/49.png", "images/50.png", "images/52.png"];
function getRandomFruit(fruits) {
var num = Math.floor(Math.random() * fruits.length);
if (num === 0) {
num = 1;
}
var fruit = fruits[num];
console.log(fruit);
}
getRandomFruit(randomFruits);
let orange = new PIXI.Sprite.fromImage(fruit);
orange.scale.set(0.6);
orange.x = (app.renderer.width / 2) + 230;
orange.y = (app.renderer.height - container.height) / 2 + 20;
app.stage.addChild(orange);
}