Quantcast
Channel: Pixi.js Latest Topics
Viewing all 3981 articles
Browse latest View live

Access pixi container children or length outside of ticker problem

$
0
0

Hello,

I decided to update banner made with pixi version  3.0.8, to use more recent version of pixi. I think the latest version where I didn't have problem was 4.3.1.

It is very basic banner. 3 images should alternate. I am using geensock for alpha tween. And when they fade out I change their child index.

They are inside container. I can access stageContainer.children.length only inside ticker (3) in the new vesrion. Outside ticker stageContainer.children.length is 0 and I also can't getChildAt(1).

I found this behaviour weird and impossible to use geensock to do the tween. Not sure if there is something wrong or it is a break change with zOrders or something.

My code is here. If you uncomment the infiniteTween function, you can't log stageContainer.children.length or stageContainer.getChildAt(numSprites - 1); because stageContainer.children.length outside the ticker is incorrect.

Can somebody explain why's that ? :-)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PIXI banner</title>
<style>
    html, body{
        margin:0;
        padding: 0;
    }
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.3.3/pixi.min.js"></script>
</head>
<body>
<canvas id="pixi-banner" width="300" height="600"></canvas>

<script type="text/javascript">

(function(){
    
var app = new PIXI.Application(300, 600, {'view': document.getElementById('pixi-banner'), backgroundColor : 0x1099bb});

var stageContainer = new PIXI.Container();

app.stage.addChild(stageContainer);

stageContainer.interactive = true;
stageContainer.buttonMode = true;
stageContainer.on("mousedown", bannerKlik);
    
var numSprites = 0;    
    
function bannerKlik(){
    window.open('http://tvnoviny.sk', '_blank');
}

function tweenComplete(sprite){
    stageContainer.setChildIndex(sprite, 0);
    sprite.alpha = 1;
    
    infiniteTween();
}

function infiniteTween(){
    
    console.log(stageContainer.children.length);
    
    var sprite = stageContainer.getChildAt(numSprites - 1);
    
    var tween = TweenLite.to(sprite, 1.5, {alpha:0});
    tween.delay(3);
    tween.eventCallback("onComplete", tweenComplete, [sprite]);
    
} 
    
var loader = new PIXI.loaders.Loader('https://static.markiza.sk/ads/2015/');
    
loader.add('img1', 'Test_19.jpg');
loader.add('img2', 'Test_23.jpg');
loader.add('img3', 'Test_26.jpg');

loader.load(function(loader, resources){
    
    var sp;
    
    for(var img in resources){
        sp = new PIXI.Sprite(resources[img].texture);
        stageContainer.addChildAt(sp,0);
    }
    
});

loader.once('complete',onAssetsLoaded);
    
function onAssetsLoaded(){
    
    app.ticker.add(function(delta) {
        app.render(stageContainer);
        //console.log(numSprites);
        console.log(stageContainer.children.length);
    });
    
    numSprites = stageContainer.children.length;
    
    //infiniteTween();
}
    
})();
</script>
</body>
</html>

 


[PIXI] Correct way to initialize an Application?

$
0
0

Hi Everyone,

Browsing through the Pixi docs, it looks like the correct way to initialize a Pixi app with an initial width and height is:

let app = Pixi.Application({width: 500, height: 500});

It looks like Application only takes a single options argument.

http://pixijs.download/release/docs/PIXI.Application.html#stage

 

However, the examples use this format:

var app = new PIXI.Application(800, 600);

http://pixijs.github.io/examples/#/basics/basic.js

The above is how v3 used to do it - is this now deprecated, and is the format in the Doc the most up to date?

 

Replacing sprite with one solid color?

$
0
0

Hi there, I've been googling this for a while but all I've come up with is how to tint the sprite which isn't the result I want (I've tested, it colorizes the sprite)

So I was wondering if it was possible to just fill the entire sprite with one solid color with no alpha channel?

Thank you!

Questions About Video File Playback...

$
0
0

Hi,

I think I saw video file playback support built into PixiJSv4.

If above is true I have the following questions:
(1) Does video file playback have audio?
(2) Does video file playback work on mobile (Android/iOS)?

Thanks!

JeZxLee

Does PixiJSv4 Have "Pixel Perfect Collisions"?

$
0
0

Hi,

Took some time, but I think I have an idea for a new game...

I need pixel perfect collisions between sprites (think 2-d space shooter).
The documentation makes absolutely no sense to me so I am asking another stupid question here:
Does PixiJSv4 have built-in pixel perfect collisions system?
(need URL link to some code and a demo)

Thanks!

JeZxLee

Extending Sprite Class

$
0
0

This is more of a JS question really. I know the solution, I just need to know why this won't work, opposed to that.

I am very new to PIXI and just barely grasping the concepts of oop so bare with me. What I'm wanting to build is an array based keyframe animation system ie (player.add.animations([3.5.9.10], walk, fps)). Of course I don't really like using game engines because I feel like I won't really be "learning" anything.

let Container = PIXI.Container, 
                autoDetectRenderer = PIXI.autoDetectRenderer,
                loader = PIXI.loader,
                resources = PIXI.loader.resources,
                Sprite = PIXI.Sprite;

        icon = function(img, type){ 
           var self = {
               img: img,
               type: type
               
           };
            
            return self;
        };

        icon.prototype = Object.create(Sprite); 
        icon.prototype.animate = function(){
            console.log("test");
            
        };

        var meow = icon("rwqerq" , "asdf"); 
        meow.animate();

So I was wondering why meow didn't inherit the .animate method, the console says its a function. I know that removing "var self = {}" and "return self;" will fix the problem, along with using "this.img = img;" and the "new" keyword will fix this problem, but again, I just want to know why this doesn't work opposed to the solution, so I can expand my general js knowledge.

 

SVG Spritesheet for PIXI

$
0
0

Hey folks!

 

I use a large number of vector image sprites in a game. At the moment I have to export them all from Illustrator as PNG's, TexturePacker those into a large spritesheet, and then load that with the PIXI loader.

I'd prefer to download an SVG rather than a PNG, if possible, to keep download size down, and so that I could theoretically draw the sprites at any scale without pixelation or interpolation (such as I would get if I had a small PNG stretched to a large scale).

I did a big investigation into this in the past, and it turned out to be rather a pain. I grouped my sprites very carefully in Illustrator with named layers, so that those names became group IDs in the output SVG. Then clientside I extracted each group into its own SVG element, put that into a blob URL, and then loaded that with Pixi loader  - which naturally doesn't work in a bunch of IE versions, and wasn't particularly fast in real browsers like FF or Chrome.

 

Is there a better/easier way that I'm, not thinking of?

how to render 30 animating lines with 2500 points each at 60fps

$
0
0

Greetings!

I love pixijs! Amazing stuff!

I'm currently attempting to plot about 30 lines, each containing about 2500 points scrolling right to left (where once a point goes off the screen to the left, a new point is appended on the right). Think a whole bunch of streaming time series charts.

I've been able to plot them out, creating a top level PIXI.Container to contain all the lines, and then for each line, creating a PIXI.Graphics object that I addChild to the top level PIXI.Container, setting the line style and then in the render loop going thru each line's 2500 points and doing the moveto lineto fun. It works! However my framerate peaks at around 40fps, which is still nice, but hoping for a 60fps. Note: I do the line moveto and lineto for each line before I call the render on the top level PIXI.Container, so hopefully that's forcing all the draw work to happen in one frame.

Does anyone happen to know if there any optimizations that I could leverage to speed this up?

Thank you kindly for any help you can offer.

Cheers!


PIXI.WRAP_MODES.REPEAT not working?

$
0
0

Hello, I'm asking because I'm not sure of my understanding  the  PIXI.basetexture WRAP_MODES:

For example:  given one container, one texture (loaded with loader) and one smaller sprite, defining PIXI.WRAP_MODES.REPEAT should fill the whole container, but it doesn't.

The following code shows a sprite inbetween the container without repeating, what I'm doing wrong ? see WRAPMODE_TEST_HERE

Thanks in advance

PS: using PIXI 4.5.5

loader.load((loader, ressources) => {
    var texture = ressources.rgba.texture;
    texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;
    var sprite = new PIXI.Sprite(texture);
    sprite.width = 312
    sprite.height = 312
    stage.addChild(sprite);
...
})

 

Keyboard input within iFrame(clicking doesn't focus)

$
0
0

Itch.io puts my game in an iFrame. This means that event listeners don't work unless the iFrame has been clicked on (so no keyboard input). But clicking on the WebGL area within the iFrame doesn't focus the iFrame! If I make the iFrame larger than the rendering area, then click on the border(area between WebGL rendering area and iFrame edge), then my iFrame is focused, and keyboard input works again. But I can't ask players to click on the border before playing! It should be that the player lands on my page, clicks on the WebGL rendering area, and starts playing. And since this is on itch.io, I can't change the .html of the parent window (the one that contains my iFrame). I'm using hexi, so I'm using pixi v3. 

Bug in my ordering code?

$
0
0

I'm trying to implement a simple "move to back" / "move to front" without relying on the heavy lifting of something like https://github.com/pixijs/pixi-display

Here's my ordering code, but it doesn't seem to always work... though it does work some of the time... I think it looks like for some of the items it works but in reverse? What am I missing? :)

//moves an item in an array to either the front or back
export const PopTo = (isFront:boolean) => items => item => {
    const copy = items.concat();
    const ret = copy.splice(copy.indexOf(item), 1);

    return (isFront) ? ret.concat(copy) : copy.concat(ret);
}
export const PopToFront = PopTo(true);
export const PopToBack = PopTo(false);


//move item to back
this.children = PopToBack (this.children) (target)
//move item to front
this.children = PopToFront (this.children) (target)

 

Pixi.js Showcase

$
0
0

Made anything cool with pixi.js? Post it up here and share it with the world!

 

Whether it's a cool game demo, a fully fledged website or some tripped-out crazy experiment, we would all LOVE to see it!

 

To get the ball rolling, here are some pixi.js projects that exist out on the internets:

 

games:

 

http://www.goodboydigital.com/runpixierun/

http://www.theleisuresociety.co.uk/fightforeveryone/

http://flashvhtml.com/

 

experiments:

 

http://gametest.mobi/pixi/morph/

http://gametest.mobi/pixi/balls/

http://www.goodboydigital.com/pixijs/bunnymark/

 

 

 

 

 

New to PixiJs: Showing percent of image revealed using mask?

$
0
0

Hello,

I'm super new to pixijs and am trying to do a scratch off type game, using the code samples from

https://pixijs.github.io/examples/#/demos/mask-render-texture.js

and

https://pixijs.github.io/examples/#/demos/batch.js

 

Wherein, there's a bunch of particles on screen, using the particle container, that you're meant to "scratch-off" within a given time limit....I've tapped into

function pointerMove(event) {
			if (dragging) {
				brush.position.copy(event.data.global);
				app.renderer.render(brush, renderTexture, false, null, false);
				
				var hits = 0;
			        var imageData = app.renderer.extract.pixels(renderTexture);

			for (var i = 0, ii = imageData.length; i < ii; i = i + 4) {
				if (imageData[i] == 0 && imageData[i + 1] == 0 && imageData[i + 2] == 0 && imageData[i + 3] == 0)
					hits++;
			}
			scratchOffPercentage = Math.ceil((hits / totalTextureSize) * 100);

			}
		}

from the mask-render-texture.js example, but doing app.renderer.extract.pixels(renderTexture); as the mouse is moving, seems to be quite taxing and makes the particles lag....is there a better way of doing this?

Essentially, with the example  https://pixijs.github.io/examples/#/demos/mask-render-texture.js in mind, can i show how much of the picture underneath is showing/has been drawn by the "brush"?

 

Thanks for any help!

 

Iterate through loaded texture atlas

$
0
0

I've loaded a large sprite sheet of trees and I want to iterate through them all so I can grab random trees. Up until now I've always just used them by name, so I'm not sure how to do this.

loader.add('trees', 'trees.json')
.on('progress', this.loadProgress)
.load(this.done);

 

Scroll/clip rect in pixijs

$
0
0

Hi All,

 

I have a quick question that ive been battling with for most of the day, is there an easy way to create a "scrollRect" for a pixi graphics object? I mean something along the lines of:

 

myGraphics.scrollRect = new Rectangle(10, 10, 100, 100);

 

That would then basically clip the while display object from x=10, y=10, cx=100, cy=100. Masks seem complete overkill here and really hard to manage, as when you move the graphics object you also have to move the mask... unless im mistaken? It seemed that the mask couldnt be added to the actual graphics object and thus its position was all out of sync with the display object. Is this something that exists but i just couldnt find it?

 

In the above example, if you move the display object to, say, 300x300 then the clip rect would be unaffected. Ive also thought that i might be able to implement this by creating a new texture of itself and drawing that based on the clip rect, i havent tried this and this may work, but it seems expensive and figured i would ask incase there is a much simpler method.

 

Thanks in advance,

Ian


CreaturePack Pixi.JS now accelerated with WebAssembly

How to draw directly to a PIXI canvas?

$
0
0

I want to use PIXI only as the rendering/drawing part of a game (engine) but I also need the possibility to draw directly (for non-sprite graphics).

I am able to get access to the canvas a) renderer.render() overwrites what I do (even if clearBeforeRender is false) and 2) I guess there's a better way?

What is the correct way make my own renderer / plugin so I can draw directly to the canvas?

Something about... PIXI.CanvasRenderer#registerPlugin

PIXI with React or Angular

$
0
0

Hello! Please tell me whether to combine the pixi with react or angular to build the UI. I'm a flash developer with AS3 and turn on JS in the world of flash, works very effectively bundle Starling + Feathers, Pixi, I have not found a decent replacement Feathers. Spend time creating a UI library from scratch is not very desirable. What would you recommend friends? Thank you.

PIXI.particles.ParticleContainer

$
0
0

I've tried using this to optimise code that doesn't really require any of the fancy stuff you'd lose out on. If I use a ParticleContainer instead of a Container, I get the following

 

\node_modules\pixi.js\lib\particles\ParticleContainer.js:214 Uncaught TypeError: Cannot read property 'baseTexture' of undefined at ParticleContainer.renderWebGL (\node_modules\pixi.js\lib\particles\ParticleContainer.js:214:57)
at WebGLRenderer.render
(\node_modules\pixi.js\lib\core\renderers\webgl\WebGLRenderer.js:371:23)
at Object.exports.noisyRegions
(js\PixiMapDrawer.js:202:11)
at Array.queue.push (\js\Game.js:182:11)
at requestAnimationFrameHandler (js\Game.js:68:10)

There's one google search result that's moderately relevant, but doesn't profer any useful solutions. Anyone come across this before and know what, if anything, I've done wrong or, if nothing, what I can do to fix it?

Remove SpriteSheet TextureCache

$
0
0

I have loaded SpriteSheet using json. Like this below.

const loader = new PIXI.loaders.Loader();
loader.add('bunny', 'data/bunny.png')
      .add('spaceship', 'assets/spritesheet.json');
loader.load((loader, resources) => {

});

I want to remove all the TextureCache which was loaded using this spritesheet.json only.

I have tried.

PIXI.Texture.removeFromCache("spaceship");
PIXI.Texture.removeTextureFromCache("spaceship");

But in PIXI.TextureCache names of all the spriteFrame were included there. And still i am able to use image form frame. Using this.

var bgSprite2 = PIXI.Sprite.fromFrame("ship1");
bgSprite2.anchor.set(0.5, 0.5);
var pos = {x: 300, y: 200};
bgSprite2.position.set(pos.x, pos.y);
stage.addChild(bgSprite2);

I want to remove all the entries of spriteFrame in TextureCache and i want to load new set of spriteFrame.

I am doing this because i have spritesheet animations of two diffrent spaceship but the individual symbol name of both spaceship are same.

Please help.

Viewing all 3981 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>