Jump to content

Ninja velocity not working


littlebuddy98
 Share

Recommended Posts

I have been having a problem with the velocity of my sprite (donut), it doesn't seem to want to use the velocity i have given it. 

The code below is what i am using (the velocity is where i draw in the donut in the create function).

 

<!doctype html>
<html lang = "en">
<head>
    <meta charset="UTF-8" />
    <title>Candy Roll</title>
    <!--<script type="text/javascript" src="js/phaser.min.js"></script>-->
    <script type="text/javascript" src="js/phaser.2.4.5.ninja-physics.min.js"></script>
    <style type="text/css">
        canvas{
            margin: auto;
        }
        body{
            margin: 0;
            background-color: black;
        }
    </style>
</head>

<body>
    <script type="text/javascript">
var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS, '', { preload: preload, create: create, update: update});

function preload (){
    game.load.image ('ledge', 'assets/wooden block.png');
    game.load.image ('background', 'assets/background3.png');
    game.load.image ('donut', 'assets/donut.png');
    game.load.spritesheet('triangle', 'assets/ninja-tiles64.png', 64, 64, 34);
    game.load.image ('woodentriangle', 'assets/wooden triangle64.png');
    game.load.image ('playbutton', 'assets/wooden play button.png');
}

function create (){
    var button;
    game.physics.startSystem(Phaser.Physics.NINJA);

    background = game.add.tileSprite(0,0, window.innerWidth, window.innerHeight, 'background');

    ledges = game.add.group();
    var ledge = ledges.create(0, 300, 'ledge');

    ledge = ledges.create(65,300, 'ledge');  
    ledges.enableBody = true;
    game.physics.ninja.enableTile(ledges);
    
  
    triangle = game.add.sprite(349, 280, 'triangle', 2);
    //game.physics.ninja.enableTile(triangle, triangle.frame);

    triangle.addChild(game.make.sprite(0, 0, 'woodentriangle'));
    triangle.inputEnabled = true;
    triangle.input.enableDrag(true);

    donut = game.add.sprite(44, 75, 'donut'); 
    donut.scale.setTo(0.03,0.03);
    game.physics.ninja.enable(donut);
    game.physics.ninja.gravity.y = 10;
    donut.body.collideWorldBounds = true;
    donut.body.fixedRotation = true;
    donut.body.velocity.x = 100;

//creating play button
button = game.add.group();
button = game.add.button(10, 10, 'playbutton', playGame, this, 2, 1, 0);  
button.scale.setTo(0.5);

function playGame(){
    triangle.addChild(game.make.sprite(0, 0, 'woodentriangle'));
    triangle.inputEnabled = false;
    triangle.input.enableDrag(false);
}
}

function update (){
    game.physics.ninja.collide(donut, ledges);
   //game.physics.ninja.collide(donut, triangle);
}
</script>
</body>
</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...