gree / lwf

LWF - Lightweight SWF
http://gree.github.com/lwf/
zlib License
627 stars 167 forks source link

Texture replacing in Javascript #128

Closed chargo closed 9 years ago

chargo commented 9 years ago

Hi, Is it possible to replace textures in Javascript? I've only found examples of Unity or Cocos-2d, like https://github.com/gree/lwf/issues/19 , but not in Javascripts/html5. Tried to assign value to lwf.data.textures[index], but nothing happened. Thanks!

splhack commented 9 years ago

Yes it is, at loading time. You can specify imageMap object or function in loadLWF parameter to replace the url of images.

https://github.com/gree/lwf/blob/master/coffee/webkitcss/lwf_webkitcss_resourcecache.coffee#L44-L51

chargo commented 9 years ago

Thank you for the fast reply. Besides, what if I want to replace some textures at runtime, like replace the score number sprites? Thanks in advance!

Edit: By load the same lwf again with different imageMap, I'm able to switch the number texture at runtime, but I wonder if there is a more efficient way to do this.

splhack commented 9 years ago

replace the score number sprites

For this case, have a movieclip symbol what has 10 key frames. Each key frame has a number bitmap and a frame label. "0" label has "0" bitmap, "1" label has "1" bitmap, ... It is a common way in Adobe Flash.