j'aurais bien voulu savoir comment on fait pour charger une image sur l'objet aprés qu'il a été créé, parce que je crée l'objet en début de page JS et ensuite je voudrais y mettre son image à partir du init().
Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 /* ****************** CLASSES ****************** */ class CObjet{ constructor(Image, PX, PY, Width, Height, Nom){ this.Image=Image; this.PX=PX; this.PY=PY; this.Width=Width; this.Height=Height; this.Nom=Nom; } } /* ******************* VARIABLES **************** */ var largeur=screen.width; var hauteur=screen.height; var image1=new Image(); var X1,X2,Y1,Y2=0; var menu=false; var monobjet=new CObjet(image1,100,200); // <----- PX et PY /* ************** FONCTIONS *************** */ function anime(timestamp){ ctx1.drawImage(monobjet.Image,monobjet.PX,monobjet.PY); animtimer=requestAnimationFrame(anime); } function init(){ ecran1.width=largeur; ecran1.height=hauteur; ctx1.width=largeur; ctx1.height=hauteur; image1.onload=function(){ monobjet.Image=image1; } // Image à charger pour l'objet. image1.src='citrouille.png'; var animtimer=requestAnimationFrame(anime); }
Partager