Javascript Webworker Problem

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Javascript Webworker Problem

    Servus Leute,
    ich hoffe es geht in Ordnung das ich hier eine Javascript Frage stelle.
    Ich möchte gerne das document element an einem Worker schicken.
    geht das überhaupt ?
    Der Grund ist ich möchte Images erstellen im Worker und ausschneiden.
    hier einmal mein Code was ich bis her versucht habe:

    Quellcode

    1. function Application(mainWindow) {
    2. this.mainWindow = mainWindow;
    3. this.userAvatar = null;
    4. this.enemyAvartar = null;
    5. this.io = new IOController(mainWindow);
    6. this.selectMenu = null;
    7. this.helper = Helper;
    8. this.workerMethods = {
    9. userAvatar : 0,
    10. enemyAvatar : 1
    11. };
    12. }
    13. Application.prototype.avatarClicked = function(e) {
    14. if (!this.userAvatar) {
    15. this.userAvatar = e;
    16. // if (this.mainWindow.Worker) {
    17. // var w = new this.mainWindow.Worker("js/worker/createSpriteWorker.js");
    18. // w.postMessage(this);
    19. // }
    20. e.setAttribute("isActiv", "true");
    21. e.firstElementChild.style.opacity = 0.7;
    22. e.firstElementChild.style.backgroundColor = "blue";
    23. } else if (!this.enemyAvartar) {
    24. this.enemyAvartar = e;
    25. // if (this.mainWindow.Worker) {
    26. // var w = new this.mainWindow.Worker("js/worker/createSpriteWorker.js");
    27. // w.postMessage(this);
    28. // }
    29. e.setAttribute("isActiv", "true");
    30. e.firstElementChild.style.opacity = 0.7;
    31. e.firstElementChild.style.backgroundColor = "red";
    32. }
    33. };
    34. Application.prototype.loadGameSceen = function(contentid) {
    35. if (this.userAvatar != null && this.enemyAvartar != null) {
    36. this.selectMenu = this.mainWindow.document.getElementById(contentid);
    37. this.selectMenu.style.opacity = 1;
    38. this.removeElementWithAnimation(this.selectMenu);
    39. } else {
    40. alert("bitte wählen sie ihren spiler aus");
    41. }
    42. };
    43. Application.prototype.removeElementWithAnimation = function(element) {
    44. var app = this;
    45. setTimeout(function() {
    46. if (element.style.opacity != 0.0) {
    47. element.style.opacity = (element.style.opacity - 0.1);
    48. app.removeElementWithAnimation(element);
    49. } else if (element.style.opacity == 0) {
    50. element.remove();
    51. }
    52. }, 30);
    53. };
    Alles anzeigen