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

Texture / Sprite Slow to add to stage

$
0
0

Hey guys.. I have a quick question. So I'm preloading a background texture right, roughly 960 x 540, so not huge in the grand scheme of things. The preloader has finished loading it, and it definitely exists in the cache, however when ever I do this...

let bg = new PIXI.Sprite(PIXI.Texture.fromImage('myBG.png'));
stage.addChild(bg);

It takes a fair while to actually add it to the stage. I've watched the network to see if it IS making another xhr request to get the same image, and it's not :(

Are there any suggestions if I'm doing something wrong? Should I make a custom cache and create all the textures first so I don't have to wait for PIXI.Texture.fromImage to hunt through the texture cache and make it?

Cheers!


Change the style of Sprite

$
0
0

FastStoneEditor1.png.31118bb7732f2b66ea18657fb663908b.png

Put a "sprite" style change is similar to CSS "border-radius" OK?

Error when creating a BitmapText object.

$
0
0

Hi,

I am trying to load a bitmap text font with PixiJS and I get this error:

Uncaught TypeError: Cannot read property 'size' of undefined
    at e.updateText (BitmapText.js:99)
    at new e (BitmapText.js:99)

The font is created with BMGlyph using the Cocos2d/BMFont settings with the font face forced to be "hudScoreFont".

Here is how I load the font:

loader.add("hudScoreFont", "assets/fonts/hudScoreFont.fnt");

And here is how I create the BitmapText object:

let txtScore = new BitmapText("00", {font: "288px hudScoreFont"});

I can see that the fnt file has been downloaded, but the png of the font is never downloaded.

If you have any insight as to what I might be doing wrong, please let me know!

 

EDIT: I am using Pixi v. 4.4.2

Retina Resolution Question

$
0
0

Hi,

I have a question about the resolution in PIXI.js: If I create a PIXI.Graphic object (for example a rectangle) with the size 50 pixels by 50 pixels, this rectangle will be the same size on my desktop machine (devicePixelRatio 1) as a 50 pixel by 50 pixel div element.

When I look at the same page with an iPad Air 2 (devicePixelRatio 2), the rectangle drawn with PIXI is twice the size of the div element. In my opinion, on the iPad, both elements should be equally large, right?

I have created a CodePen: http://codepen.io/fresh5/pen/jBxNjO

Thanks for your support!

render problem on ipad4

$
0
0

Hi guys,

I tested my game on ipad4, and sometimes a few sprites can not be displayed(most of the time is the bg image), but the rest are rendered normally,
since it does not happen every time, and it only happen on ipad4, moreover, it does not pop out any error, it's really hard to find the cause,
does anyone know what could be the possible cause to this sort of partially render problem?

motion path in pixi?

$
0
0

How to create motion path in pixi or has plugin motion path in pixi? Thanks

Only catch events on canvas

$
0
0

Hi,

I'm trying to make a HTML UI over my canvas-based game. It works fine, except every click on my UI overlay also triggers a click on the canvas - it seems PIXI adds listeners to the window object (when I inspect the events received by the canvas, the original target is the window). I'm not sure how to disable that or if there's some kind of approved, not hacky workaround. I would want to only receive PIXI events if they interact with the canvas directly.

Guide to pixi-V4 filters

$
0
0

V4 filters are differ from V3. You can't just put there shader and assume that texture coords are in [0,1] range.

I am sorry that you have to learn all of that, and I will make sure that the process will be easier for pixi-v5.

Filter Area

Thanks to @bQvle and @radixzz

First, lets work with the AREA. When you apply filter to container, PIXI calculates the bounding box for it. We are working with bounding box.

Invariant: maximal vTextureCoord multiplied by "filterArea.xy" is the real size of bounding box.

Don't try to think about it: its like that because of performance reasons, its not logical in user-experience sense. Neither vTextureCoord dimensions, neither filterArea.xy are predictable, but they multiplication is what we need. 

Area can have padding, so please don't use it to get "displacement texture" coordinates or any second-hand textures you are adding to the shader, use "mappedMatrix" for it (see below)

If you want to get the pixel coordinates, use "uniform filterArea", it will be passed to the filter automatically.

uniform vec4 filterArea;
...
vec2 pixelCoord = vTextureCoord * filterArea.xy;

They are in pixels. That wont work if we want something like "fill the ellipse into a bounding box". So, lets pass dimensions too! PIXI doesnt do it automatically, we need manual fix:

filter.apply = function(filterManager, input, output)
{
  this.uniforms.dimensions[0] = input.sourceFrame.width
  this.uniforms.dimensions[1] = input.sourceFrame.height

  // draw the filter...
  filterManager.applyFilter(this, input, output);
}

Lets combine it in shader!

uniform vec4 filterArea;
uniform vec2 dimensions;
...
vec2 pixelCoord = vTextureCoord * filterArea.xy;
vec2 normalizedCoord = pixelCoord / dimensions;

Here's the fiddle: https://jsfiddle.net/parsab1h/ . You can see that shader uses "map" and "unmap" to get to that pixel

Now let's assume that you somehow need real coordinates on screen for that thing. You can use another component of filterArea, zw:

uniform vec4 filterArea;
...
vec2 screenCoord = (vTextureCoord * filterArea.xy + filterArea.zw);

I dont have an example for that, but may be you need that value for something?

Fitting problem

Thanks to @adam13531 at github.

One small problem: those values become wrong when PIXI tries to fit bounding box: here's the fiddle: http://jsfiddle.net/xbmhh207/1/

Please use this line to fix it:

filter.dontFit = true;

Bleeding problem

Thanks to @bQvle

The temporary textures that are used by FilterManager can have some bad pixels. It can bleed. For example, displacementSprite can look through the edge, try to move mouse at the bottom edge of http://pixijs.github.io/examples/#/filters/displacement-map.js. You see that transparent (black) zone, but it could be ANYTHING if it wasnt clamped. To make sure it doesnt happen in your case, please use clamping after you map coordinates:

uniform vec4 filterClamp;

vec2 pixelCoord = WE_CALCULATED_IT_SOMEHOW
vec2 unmappedCoord = pixelCoord / filterArea.xy;
vec2 clampedCoord = clamp(unmappedCoord, filterClamp.xy, filterClamp.zw);
vec4 rgba = texture2D(uSampler, clampedCoord);

Both FilterClamp and FilterArea are provided by FilterManager, you dont have to calculate pass it in "filter.apply", here's pixi code that takes care of that: https://github.com/pixijs/pixi.js/blob/dev/src/core/renderers/webgl/managers/FilterManager.js#L297

OK, now we have "transparent" zone instead of random pixels. But what if we want it to be fit completely?

displacementFilter.filterArea = app.screen; // not necessary, but I prefere to do it.
displacementFilter.padding = 0;

That'll do it. Why did I modify filterArea there, PIXI will "fit" it anyway, right? I dont want PIXI to have time calculating the bounds of container, because maggots are actually changing it, crawling in places that we dont see! 

No extra transparent space, and if you put it into http://pixijs.github.io/examples/#/filters/displacement-map.js , and you move mouse to bottom edge, you'll see the grass.

Mapped matrix

When you want to use extra texture to put in the filter, you need to position it as a sprite somewhere. We are working with sprite that is not renderable but exists in the stage. Its transformation matrix will be used to position your texture in the filter. Please use https://github.com/pixijs/pixi.js/blob/dev/src/filters/displacement/DisplacementFilter.js and http://pixijs.github.io/examples/#/filters/displacement-map.js as an example.

Look for a mapped matrix: 

this.uniforms.filterMatrix = filterManager.calculateSpriteMatrix(this.maskMatrix, this.maskSprite);

maskMatrix is temporary transformation that you have to create for the filter, you dont need to fill it. Sprite has to be added into stage tree and positioned properly.

You can use only texture that are not trimmed or cropped. If you want the texture to be repeated, like a fog, make sure it has pow2-dimensions, and specify it in baseTexture before its uploaded on GPU/rendered first time!

texture.baseTexture.wrapMode = PIXI.WRAP_MODES.REPEAT;

If you want to use an atlas texture as a secondary input for a filter, please wait for pixi-v5 or do it yourself. Add clamping uniforms, use them in shader and make better mapping in "filterMatrix"


Light cookies, using masks for retro lighting on tileset game

$
0
0

Hi guys,

I've been making a game project recently which I wanted to add some relatively basic lighting effects to. I really struggled with anything I found online and basically everything seems broken. After researching alpha masking and texture rendering at runtime I've come up with a demo which finally puts the entire piece together so people can use it.

I really hope this makes a difference to peoples learning experience, their games and their appreciation for PixiJS.

I welcome any mods to the pen as I'm not the best at writing super hot JS, I just want it to work.

The demo includes moving a light cookie, changing its alpha, and overlaying a rectangle to emulate day/night - all which blend together nicely.

Quote

THIS REQUIRES NOTHING MORE THAN PIXIJS

The code can be found here: 

 

Thanks a lot guys,

Some footage inside a working game demo can be seen here:

And some more of my game concept can be seen here: 

 

This is the effect it has when used as lighting in my game, keeping in mind i have extra shadows on the tileset:

 

kmWIPGK.png

 

Jammy.

 

Creating non-connected circles with graphics.arc()

$
0
0

Hi all, 
I'm using graphics.arc() to make two circles that aren't joined

Here's a basic example - 

As you can see the circles are joined - how do I avoid this? 

Cheers in advance!

Pixi.js v4 get globally translated vertices for collision detection

$
0
0

Hi, I'm running into an issue regarding collision detection against adjacent DisplayObjects. Let's say I have sibling objects that are a child of a Container that has been rotated. If I use getBounds() on the siblings they return a bounding box that is oriented to cardinal north. Using those bounds for collision detection may result in false positives, because the given bounds may not follow the actual shape and orientation of the DisplayObject. I created a codepen to illustrate the point: 

When you toggle the "rotate" buttons at the bottom of the pen you will see the purple box morphing to the shape of the bounds for "shape" and "label". The text will change from red to green if the collision detection returns positive.

I would like to do a more robust collision detection algorithm (possibly based on Separating Axis Theorem), but I would need to grab the vertices for each shape correctly translated to the global coordinates regardless of their nesting within the scene graph (accounting for scale, rotation, and translation from the shape and all parent transforms). The case being that the collision detection that I would like to do may not be only between direct siblings within the scene graph.

Is there a nested property that would give me what I'm looking for, or will I need to grab the graphics data and apply all of the recursive parent transforms myself for each vertex?

 

Here is a fork of a codepen that demonstrates the Separating Axis Theorem: 

 

Graphics scale and linewidth

$
0
0

Is there a way to scale a Graphics without getting the linewidth scaled as well?

For instance:

var stage = new PIXI.Container();
var graphics = new PIXI.Graphics();

// Set a fill and line style.
var linewidth = 10;
graphics.beginFill(0xFF3300);
graphics.lineStyle(linewidth, 0xffd900, 1);

// Draw a shape.
graphics.moveTo(50, 50);
graphics.lineTo(250, 50);
graphics.lineTo(100, 100);
graphics.endFill();

// Now, scale this Graphics.
var scale = 5;
graphics.scale.set(scale, scale);  // all lines now have width linewidth * scale

In the example above, the vector "shape" gets properly scaled by a factor of 5. Unfortunately, so does the linewidth.

I am trying to render Graphics vector data on top of Google Maps (typically polygons over countries), and when the map gets zoomed in, I want to rescale the data without getting enormous boundaries.

Dancing TextField with right align

$
0
0

Hello,

I have two TextFields. The first one is aligned right by setting anchor.x = 1. The second one is aligned left by default.

There is a visual issue if text value of the RIGHT aligned TextField is changing on the different one with different width: the digits are "dancing" a little, while the LEFT aligned TextField stands. Here is the example: https://jsfiddle.net/7dv61c63/

Don't know is it a bug at PIXI but I'll be much appreciated for any suggestion how to fix this issue.

MS Edge extra strong Antialias

$
0
0

Hello,

We are using pixi v4 (through haxe), and we have some very very strong antialias on ms edge browser. In fact it's so strong it might look better without :/ We used antialias = true.

Here is a screenshot showing chrome (on left) and edge (on right), as you can see, image gets really blurry. The png in the sprite sheets have better resolution than what I display in the pic, that is not the cause. Game is simply scaled down.

I have no idea what causes this or how to workaround/solve the issue. Any hint is welcome.

 

Chrome vs Edge.png

How on earth do I change the color of text?

$
0
0
var name_text = new PIXI.Text(name);

name_text.style.font = "bold 10px arial";

name_text.style.align = "center";

this.imageContainer.addChild(name_text);

 

 

How do I change the color  ! aaa

 

 


how to use pixijs loader with holwer.js?

$
0
0

how to use pixijs loader with holwer.js

Interact with line

$
0
0

Hello,

I want to create resize-able room by dragging

Currently to interact with line, I'm create transparent React over line to make interact but it did not work well when line is curved

How should I do to get interact with line ?

 

drawWalls() {
        this.lineStyle(30, 0, 1);
        this.beginFill(defaultVal(this._options.backgroundColor, 0xe74c3c), 1);
        this.moveTo(this._options.points[0].x, this._options.points[0].y);
        let totalPoints = this._options.points.length;
        for (let i = 1; i < totalPoints; i++) {
            this.addChild(new Wall([this._options.points[i - 1], this._options.points[i]])); // my interact overlay
            this.lineTo(this._options.points[i].x, this._options.points[i].y);
        }
        this.endFill();
    }

 

Untitled-1.jpg

Issues with tile based game and render texture

$
0
0

Hi there,

I'm working on a tile based game using PIXI but as it is a commercial project I can't share the code. I was hoping if I explained what I'm doing someone more experienced may be able to give me some input if it is something you have come across already? 

Initially had some issues with lines between tiles when moving the container that holds them, but this was resolved in a number of ways such as not using texture packer, PIXI.SCALE_MODES.NEAREST and making sure to round off the x, y values so they are always integers, simple enough to fix.

Then having noticed was getting a poor fps on mobile I decided was time to optimise.  Initially I tried culling tiles not in view, but I didn't notice a huge performance difference with this.  So I decide I should use a render texture, and render the entire map container to the texture each frame.  This gave me a huge boost when testing on mobile, I'm a happy man :) but then... the lines between tiles are back when moving the container...

There are quite a few dynamic tiles such a platforms that move etc, hence why rendering the entire container.  So my next step is to try and be smart and split it into two containers, static and dynamic, refresh the dynamic container and only update the static one when I need to (preferably just once at the beginning).  Now I'm wondering if this would even work, as when I move the map container to move the player the static tiles, although they don't move individually, will still need updating every frame to get smooth movement. 

I want to stick with render textures as I feel this is the correct way to go about it, and that perfomance boost :) But wonder am I missing something here.  The Tilingsprite class for instance is not one I understand well, I think perhaps I could use it here? 

Thanks and apologies for a long post without a specific question.

Cheers,

Owlzy

 

Rendering interactive graph with thousands of vertices and edges

$
0
0

hi Folks,

I am new to here and I'm trying to find out whether pixijs could be a good choice for me.

What I need to do is render a possibly very large graph on the canvas, like the attached picture shows. As a bottom line, I need to draw like thousands of vertices and maybe 4-10 times of that many edges on the canvas and still stay responsive to user actions like panning around, zooming and selecting nodes and moving nodes around( the attached edge should be updated while moving). Other stuff like highlight and scale some vertex/edge I think should be trivial. 

No layout computing is required. The graph layout is calculated in advance.

I've tried some other frameworks like fabricjs and echarts. They could not handle more than 1000 vertices.

My questions is pixijs suitable for such task? And can I achieve the performance goal with reasonable amount of tweaks?

 

Thanks in advance!

social-network.png

Has anyone tried using p2.js or other physics engines with PIXI.js?

$
0
0

I have tried p2.js but I am unable to make it work in PIXI.js.  Can anyone point out what is wrong? I just want to make a simple program that if I click on the canvas a ball will be created and fall down. 

 

Viewing all 3979 articles
Browse latest View live


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