Jump to content

Ninja velocity not working


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">
    <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">
            margin: auto;
            margin: 0;
            background-color: black;

    <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;

    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;
    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;

    donut = game.add.sprite(44, 75, '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);  

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

function update (){
    game.physics.ninja.collide(donut, ledges);
   //game.physics.ninja.collide(donut, triangle);

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.

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.


  • Recently Browsing   0 members

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