2014-09-17 5 views
1

저는이 간단한 문제에 정말로 매달 렸습니다. 나는 주위를 둘러 보았고 "해결 된"해결책을 찾았지만 제 목표를 달성 할 수는 없었습니다. 내 스테이지/캔버스에 createjs.Bitmap() 객체로 버튼 이미지를로드하려고합니다. 문서 및 자습서에 나와있는 것처럼 정확하게 작업하고 있으며 이미지를 실제로 캔버스에 표시 할 수없는 것처럼 보입니다.createjs.Bitmap() 이미지가 표시되지 않습니다.

// GLOBAL VARIABLES 
var gameCanvas;    // The canvas the game will be contained within 
var gameStage;    // The primary stage holding all of our game elements 
var mainMenuContainer;  // The container for the main menu elements 

// INITIALIZATION METHODS 
// init() - sets up the game gameStage and game elements. This gets called by the <body> onLoad() event 
function init() { 
    // initialize gameStage to manage all of the game elements 
    gameStage = new createjs.Stage("gameCanvas"); 

    // add a ticker to the gameStage object 
    createjs.Ticker.on("tick", gameStage); 

    // initialize the main menu for our game 
    initMainMenu(); 

    // update the stage 
    gameStage.update(); 
} 

// initMainMenu() - sets up the mainMenuContainer element and attaches all of the main menu game elements to the 
// container. This is called from the main init() function when the main menu is ready to be initialized 
function initMainMenu() { 
    // initialize the container to manage all of the elements to be displayed on the main menu 
    mainMenuContainer = new createjs.Container(); 

    var mainMenuStartBitmap = new createjs.Bitmap("../static/img/gui/mainMenuStartButton.jpg"); 

    // add all elements of the main menu to the mainMenuContainer 
    mainMenuContainer.addChild(
     mainMenuStartBitmap 
    ); 

    // add the mainMenuContainer to the gameStage 
    gameStage.addChild(mainMenuContainer); 

    // update the stage 
    gameStage.update(); 
} 

사람이 내가 비트 맵을 생성하고 단계/컨테이너에 아이를 추가 해요 방식에 문제가 아무것도 볼 수 있습니까 : 다음은이와 관련된 game.js 파일입니까?

답변

2

스테이지를 업데이트해도 이미지가로드되지 않습니다.

당신은해야 하나 :

  • 가 지속적 무대를 업데이트합니다. 이미지가로드되면 이미지가 표시됩니다.
  • image.bitmap.onload 이벤트를 수신하고 해당 지점에서 스테이지를 다시 업데이트하십시오.
  • 스테이지를 그리고 업데이트하기 전에 이미지를 미리 미리로드하십시오. PreloadJS를 사용하여 그렇게. http://preloadjs.com

환호.

+0

onLoad는 마술처럼 보였고 더 깨끗하게 보입니다. 감사! 작은 샘플의 경우 –

+0

인 경우 스테이지를 불필요하게 업데이트하는 것보다 확실히 onload가 좋습니다. 더 큰 것은 무엇이든, 전체 미리로드하는 것이 좋습니다. 다행이야! – Lanny