Jump to content

Newbie With HTML5


Rayj
 Share

Recommended Posts

What have you tried? There are a lot of tutorials around the internet. The examples have a readme that explains how to get them running. Pixi's readme has basic usage examples.

 

If you have never written a line of html/js them Pixi may not be the best place to start. Read through the MDN for a bit.

Link to comment
Share on other sites

What have you tried? There are a lot of tutorials around the internet. The examples have a readme that explains how to get them running. Pixi's readme has basic usage examples.

 

If you have never written a line of html/js them Pixi may not be the best place to start. Read through the MDN for a bit.

I am trying an example at:  http://modernweb.com/2013/11/04/building-a-parallax-scrolling-game-with-pixi-js/#comment-78088

You can see the demo in action here:  http://www.yeahbutisitflash.com/pixi-parallax-scroller/final/index.html

 

The initial stage light grey on black is fine.

But from the point where it says the stage turns green and forward, it does not work!

I followed the tutorial directly. Here is where I left off. Please let me know where I went wrong.

 

<html>

          <head>

    <meta charset="UTF-8">

    <title>Parallax Scrolling Demo</title>

<meta charset="UTF-8">

    <title>Endless Runner Game Demo</title>

    <style>

      body { background-color: #000000; }

      canvas { background-color: #222222; }

    </style>

  </head>

  <body onload="init();">

        <div align="center">

                <canvas id="game-canvas" width="512" height="384"></canvas>

        </div>

        <script src="pixi.js-master/bin/pixi.js"></script>

<script>

    function init() {

stage = new PIXI.Stage(0x66FF99);

renderer = PIXI.autoDetectRenderer(

    512,

    384,

    document.getElementById("game-canvas")

  );

var farTexture = PIXI.Texture.fromImage("resources/bg-far.png");

far = new PIXI.Sprite(farTexture);

  far.position.x = 0;

  far.position.y = 0;

^?stage.addChild(far);

var midTexture = PIXI.Texture.fromImage("resources/bg-mid.png");

  mid = new PIXI.Sprite(midTexture);

  mid.position.x = 0;

  mid.position.y = 128;

  stage.addChild(mid);

requestAnimFrame(update);

    }

function update() {

  far.position.x -= 0.128;

  mid.position.x -= 0.64;

  renderer.render(stage);

  requestAnimFrame(update);

}

  </script>

  </body>

</html>

Link to comment
Share on other sites

Well that tutorial looks like it written for Pixi v2, and if you downloaded the latest from GitHub that is v3. So they are not compatible.

 

As far as your code:

  • there is a random "^?" in there, which I think might have been a copy-paste error but otherwise is a syntax error.
  • Replace the Stage with a normal Container.
  • You are also using requestAnimFrame which isn't a thing anymore in v3, you should be using the standard requestAnimationFrame().
  • The third parameter of autoDetectRenderer is options to pass the renderer, not the element. Instead do { backgroundColor: 0x66FF99, view: document.getElementById('game-canvas') }

Here is a working, cleaned up version:

<html>  <head>    <meta charset="UTF-8">    <title>Parallax Scrolling Demo</title>    <meta charset="UTF-8">    <title>Endless Runner Game Demo</title>    <style>      body { background-color: #000000; }      canvas { background-color: #222222; }    </style>  </head>  <body onload="init();">    <div align="center" id="container">      <canvas id="game-canvas" width="512" height="384"></canvas>    </div>    <script src="pixi.js-master/bin/pixi.js"></script>    <script>        function init() {          stage = new PIXI.Container();          renderer = PIXI.autoDetectRenderer(512, 384, { backgroundColor: 0x66FF99, view: document.getElementById('game-canvas') });          far = new PIXI.Sprite.fromImage("resources/bg-far.png");            far.position.x = 0;            far.position.y = 0;          stage.addChild(far);                    mid = new PIXI.Sprite.fromImage('resources/bg-mid.png');            mid.position.x = 0;            mid.position.y = 128;          stage.addChild(mid);          update();        }        function update() {          far.position.x -= 0.128;          mid.position.x -= 0.64;          renderer.render(stage);          requestAnimationFrame(update);        }  </script>  </body></html>

You could see a lot of these errors by opening up the developer console (Ctrl+Shift+I or F12 in Chrome) and seeing the errors in the Console tab.

Link to comment
Share on other sites

Well that tutorial looks like it written for Pixi v2, and if you downloaded the latest from GitHub that is v3. So they are not compatible.

 

As far as your code:

  • there is a random "^?" in there, which I think might have been a copy-paste error but otherwise is a syntax error.
  • Replace the Stage with a normal Container.
  • You are also using requestAnimFrame which isn't a thing anymore in v3, you should be using the standard requestAnimationFrame().
  • The third parameter of autoDetectRenderer is options to pass the renderer, not the element. Instead do { backgroundColor: 0x66FF99, view: document.getElementById('game-canvas') }

Here is a working, cleaned up version:

<html>  <head>    <meta charset="UTF-8">    <title>Parallax Scrolling Demo</title>    <meta charset="UTF-8">    <title>Endless Runner Game Demo</title>    <style>      body { background-color: #000000; }      canvas { background-color: #222222; }    </style>  </head>  <body onload="init();">    <div align="center" id="container">      <canvas id="game-canvas" width="512" height="384"></canvas>    </div>    <script src="pixi.js-master/bin/pixi.js"></script>    <script>        function init() {          stage = new PIXI.Container();          renderer = PIXI.autoDetectRenderer(512, 384, { backgroundColor: 0x66FF99, view: document.getElementById('game-canvas') });          far = new PIXI.Sprite.fromImage("resources/bg-far.png");            far.position.x = 0;            far.position.y = 0;          stage.addChild(far);                    mid = new PIXI.Sprite.fromImage('resources/bg-mid.png');            mid.position.x = 0;            mid.position.y = 128;          stage.addChild(mid);          update();        }        function update() {          far.position.x -= 0.128;          mid.position.x -= 0.64;          renderer.render(stage);          requestAnimationFrame(update);        }  </script>  </body></html>

You could see a lot of these errors by opening up the developer console (Ctrl+Shift+I or F12 in Chrome) and seeing the errors in the Console tab.

Thanks for the info.  I did see some of these error in Chrome, but I didn't know this example was not compatible with v3.0.6.

Could you point me to an example with source code that is compatible with v3.0.6?

 

Thanks,

 

Ray

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