Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New to Enchant.js and new to js, and want to know what is wrong with my code

So my code displays nothing I followed a sample code on the enchant.js website. Could someone please tell me what I'm doing wrong.

Here is the sample code i followed
JavaScript
// This sample shows an image that will move to the right when clicked
enchant();
window.onload = function () {
    var game = new Game(320, 320);
    game.preload('chara0.gif');
    game.onload = function() {
        var scene = new Scene();
 
        var sprite = new Sprite(32, 32);
        sprite.image = game.assets['chara0.gif'];
        scene.addChild(sprite);
 
        sprite.addEventListener('touchstart', function() {
            sprite.x += 1;
        });
 
        game.pushScene(scene);
    };
    game.start();
};


and here is my code

//index.html
HTML
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Game.js</title>        
        <script src="js/enchant.js"></script> 
        <script src="js/main.js"></script>        
    </head>
    <body>
    </body>
</html>


//main.js

C#
enchant();
window.onload = function(){
//Setting up the game
var game = new  Core(500, 700);
//preloading the res
game.preload('res/ghost.png');
// setting the fps view and onload
game.fps = 20;
game.scale = 0;
game.onload = function(){
//setting up the scene
    var mainFrame = new Scene();
    mainFrame.backgroundColor = 'blue';
    //loading image from preload into mainframe
    var playerOne = new Sprite(32, 32);
    playerOne.image = game.assets['res/ghost.png'];
    //finallying wellcome to the game ghost.
    mainFrame.addChild(playerOne);

    //moving ghost aka playerOne around.
    playerOne.addEventListener('touchstart', function(){
        if(LEFT_BUTTON_DOWN){
            playerOne.x +=0.1;
        }
    });
    //game.pushScene(mainFrame);
    game.rootScene.addChild(mainFrame);

}
game.start(); 

};
Posted
Updated 20-Jul-14 8:15am
v3
Comments
Kornfeld Eliyahu Peter 20-Jul-14 4:44am    
Go and debug your code!
Member 10957930 20-Jul-14 14:18pm    
I did what I could but still not working it makes no sense at all for the most part it's the sample code but just rewritten by me with a different image some add folders and comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900