"Pixi.js start from scratch" using the Pixi game engine

Source: Internet
Author: User
Tags addchild

This example simply demonstrates how to create a Pixi project and make a scrolling scene.

First download Source: https://github.com/GoodBoyDigital/pixi.js

1. Configure the canvas:

        Body {background-color: #000000;}        Canvas {background-color: #222222;}     </style>    <script type= "Text/javascript" src= "Lib/pixi.js-master/bin/pixi.dev.js" ></script> 

2. Include Pixi.js in the code:

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

3. Create an initialization method:

<body onload= "Init ();" >

4. Initialization method:

<body onload= "init ()" > <div align= "center" > <canvas id= "Game-canvas" width= "Up" height= "384" > </canvas> </div> <script>functioninit () {Console.log ("Init () successfully called."); //first define a stage             This. Stage =NewPIXI. Stage (0x66ff99); //create a render to render the stage to the browser             This. Renderer =Pixi.autodetectrenderer (512,                    384, {view:document.getElementById ("Game-canvas")}            ); //Create a vision material            varFartexture = PIXI. Texture.fromimage ("Resources/bg-far.png"); //Seamless cycle scrolling, requires the use of Tilingsprite, where the wide height has been written dead, can also be used through fartexture.basetexture.width,fartexture.basetexture.height to obtain dynamic wide              This. Far =NewPIXI. Tilingsprite (fartexture,512,256);  This. far.tileposition.x = 0;  This. FAR.TILEPOSITION.Y = 0;  This. Stage.addchild ( This. Far); //Close-up material            varMidtexture = PIXI. Texture.fromimage ("Resources/bg-mid.png"); //Close -up sprite, same             This. mid =NewPIXI. Tilingsprite (midtexture,512,256);  This. mid.position.x = 0;  This. MID.POSITION.Y = 128;  This. Stage.addchild ( This. mid); //Render Browser Screen             This. Renderer.render ( This. Stage); //Animationrequestanimframe (update); }        functionUpdate () { This. far.tileposition.x-= 0.128;  This. mid.tileposition.x-= 0.64;            Renderer.render (stage); //Cyclic scrollingrequestanimframe (update); }    </script></body>

Project Download: Http://files.cnblogs.com/files/theodore/scrollpixi.rar

"Pixi.js start from scratch" using the Pixi game engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.