hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

Use of addImage #92

Closed alexac1970 closed 11 years ago

alexac1970 commented 11 years ago

Hi, I'm trying to use director.addImage function to add a new image as explained in http://labs.hyperandroid.com/static/CAAT-Samples/tutorials/t4-3.html

It's not working for me. I get an "Uncaught TypeError: Type error" message in the console when i try to use the image. These are the relevant lines:

 director.addImage("imagenIlusion", "imagenes/colores.jpg", false);
 var imagenIlusion = new CAAT.Actor().setBackgroundImage(director.getImage("imagenIlusion"), false ).setBounds(10, 10, 20, 20);
 director.scenes[director.getCurrentSceneIndex()+1].addChild(imagenIlusion); 
 director.switchToNextScene(100,false,true);

Do i need to call setImagesCache? Also, is there a way to know when the image is ready to use?

Thanks.

vkbsb commented 11 years ago

You have to load the Image first before adding it to the director.. new CAAT.ImagePreloader().loadImages( [ {id:'imagenIlusion', url:'imagenes/colores.jpg'} ], function( counter, images ) { if ( counter==images.length ) { director.addImage('imagenIlusion', images[0], false); } }

hyperandroid commented 11 years ago

Check any demos sample which uses images. What VKBSB says is completely right. Regards,