javascript - using preload.js and create.js load an image? - Stack Overflow

I am following up with a game development tutorial for windows 8 here .The tutorial probably needs up

I am following up with a game development tutorial for windows 8 here /. The tutorial probably needs updating since at some point i had to add in createJS before using PreloadJS.

example:

stage = new createjs.Stage(canvas);
preload = new createjs.PreloadJS();

or else the debugging throws errors.

However the program breaks when bgImage is initialised. Any suggestive codes i can use?

bgImage = preload.getResult("screenImage").Result;
bgBitmap = new Bitmap(bgImage);
bgBitmap.scale_X = SCALE_X;
bgImage.scale_Y = SCALE_Y;
stage.addChild(bgBitmap);
stage.update();

I am following up with a game development tutorial for windows 8 here http://www.sitepoint./creating-a-simple-windows-8-game-with-javascript-game-basics-createjseaseljs/. The tutorial probably needs updating since at some point i had to add in createJS before using PreloadJS.

example:

stage = new createjs.Stage(canvas);
preload = new createjs.PreloadJS();

or else the debugging throws errors.

However the program breaks when bgImage is initialised. Any suggestive codes i can use?

bgImage = preload.getResult("screenImage").Result;
bgBitmap = new Bitmap(bgImage);
bgBitmap.scale_X = SCALE_X;
bgImage.scale_Y = SCALE_Y;
stage.addChild(bgBitmap);
stage.update();
Share Improve this question edited Nov 4, 2013 at 2:17 Jim Counts 12.8k9 gold badges47 silver badges63 bronze badges asked Nov 6, 2012 at 22:14 Piotre98Piotre98 1831 gold badge3 silver badges12 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Please make sure you are using correct syntax.

var bgImage = preload.getResult("screenImage").result;
var bgBitmap = new createjs.Bitmap(bgImage);
stage.addChild(bgBitmap);

Also what is the bug you are getting? Here is a quick example that should help.

function init() {
        canvas = document.getElementById("testCanvas");

        //check to see if we are running in a browser with touch support
        stage = new createjs.Stage(canvas);
        createjs.Ticker.setFPS(24);
        createjs.Ticker.addListener(stage);

        images = images || {};
        var manifest = [
            {src:"image.jpg", id:"image"}
        ]

        loader = new createjs.PreloadJS(false);
        loader.onFileLoad = handleFileLoad;
        loader.onComplete = handleComplete;
        loader.loadManifest(manifest);
    }

    function handleFileLoad(o) {
    //You could store all your images in object to call them easily.  
    if (o.type == "image") {
            images[o.id] = o.result;
        }
    }

    function handleComplete(event) {
        var bg = new createjs.Bitmap(loader.getResult("image").result);
        //OR samething
        //var bg = new createjs.Bitmap(images['image']);
        stage.addChild(bg);
    }

    function tick() {
        stage.update();
    }

Hope this helps.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744987366a4604691.html

相关推荐

  • javascript - using preload.js and create.js load an image? - Stack Overflow

    I am following up with a game development tutorial for windows 8 here .The tutorial probably needs up

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信