+ 10
How to make different objects in canvas
I have made a drawing[ star] and now i want that multiple stars like that can be created..My question is can i reference that star drawing..Maybe i can make it a object and then but i am not able to do that...Can anyone plz help me to do this
4 Answers
+ 13
you can create an array to hold the coordinates of the starts and then iterate all over them, drawing each one
+ 11
first, how do you draw the star?
it could help if i have more info
the general idea is a function that draws an object at a given points (given as parameters)
from there it's simply sending different parameters each time
imagine we drawing a rectangles with x,y width and height
function drawObj(obj){
draw(obj.x, obj.y, obj.width, obj.width)
}
of course this is just a simplified code
but the idea is that you can call the function like so if you have an array of objects:
for(var i=0;i<objects.length;i++){
drawObj(objects[i]);
}
and each object will be drawn on a different place
+ 4
Burey i didn't got you can you elaborate plz