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

set and cancel fullsreen mode in mobile.

$
0
0

How to set and cancel pixi game in mobile. I use some code but not work:

if (document.documentElement.requestFullscreen) {
            document.documentElement.requestFullscreen();
        } else if (document.documentElement.mozRequestFullScreen) {
            document.documentElement.mozRequestFullScreen();
        } else if (document.documentElement.webkitRequestFullscreen) {
            document.documentElement.webkitRequestFullscreen();
        } else if (document.documentElement.msRequestFullscreen) {
            document.documentElement.msRequestFullscreen();
        }

 


PIXI Load video fallback type

$
0
0

Hi,

I'm just experimenting with some video in pixi.

I've got the basic player working as per the example on the GoodBoy site - but, I now need to make it a bit more production ready, which means it needs to be able to handle different video types.

Is there a way of setting fallback video types? (So the loader can pick the type that works in that browser?)

Thanks!

Access renderer from child classes

$
0
0

I want to render a Graphic into a RenderTexture via `app.renderer.render(graphics, renderTexture)` but problem is the code is running from a subClass extends PIXI.Sprite.

The question is: Whether it's possible to access the renderer from child class?

After googling a while I still didn't find an answer.

Mask issue with Webgl renderer

$
0
0

Hi, All :)
I'm relatively new to PixiJS and I'm facing an issue that I don't understand.
 

# What I'm trying to accomplish :

Basically I create a sprite based on an image and then I display a sort of black overlay over it.

The idea is to let the user see through the black overlay thanks to a mask which will move according to user mouse movement.

The mask texture is created using multiple graphics and filters rendered by a second webgl renderer.

 

# The issue I'm facing

Sometimes (~50% of the time) when I reload the page online, the mask is invisible. It's as if there isn't any mask applied to the black overlay whereas locally it's always working.

Attached to this post you will find two pictures :

The first one represents the black overlay with the mask which is not working.

The second one represents the black overlay with the mask which is working.

I'm using the latest release of PixiJS and the source code for this example can be found here : https://jsfiddle.net/vhynmdxh/

If someone has already solved this type of issue I would be happy to discuss with them :).

Thanks.

filter-not-working.png

filter-working.png

Going from Processing / P5 to Pixi questions

$
0
0

Hi

Just wondering if any of you could help me beginning to use Pixi.  I normally use Processing & P5, and these are the main things I'm not sure of at the minute..

How would I do the following matrix / global type transformations in Pixi..

push();
translate(100,50);
scale(.5);
pop();

 

also, how would I create an overlay layer, independent of the global transformations above, so that I can place UI elements or HUD text.

Thanks for now.   

 

beginner question: using shaders in pixi v4 (custom filter)

$
0
0

Hi, this is my first time using shaders and the new filters in pixi v4, so please bare with me :ph34r:

First of all I'm a bit confused by the term (custom) filter.. Is that the same as the user of a shader? I assume it is. 

Second I tried using this example. I got it to work in pixi 3.x but somehow I can't figure out what i'm doing wrong in v4. no error messages, just a black canvas. 

My goal is to create custom button hovers with PIXI, using shaders, etc. I tried 2 different ways but... alas, same black canvas

HTML:

<a href="#" class="btn btn-one">
  <canvas></canvas>
  <span class="title">button effect one</span>
</a>

shader.frag:

  precision mediump float;
  
  uniform vec2 mouse;
  uniform vec2 resolution;
  uniform float time;

  void main() {
    gl_FragColor = vec4( sin(time), mouse.x/resolution.x, mouse.y/resolution.y, 1.0);
  }

JS:

    var btnOne = document.querySelector('.btn-one');
    var width = btnOne.clientWidth;
    var height = btnOne.clientHeight;
    var app = new PIXI.Application({
      width: width,
      height: height,
      view: btnOne.querySelector('canvas')
    });
    
    btnOne.append(app.view);

    // create rect to fill the button and apply shaders to
    
    const rect = new PIXI.Graphics()
        .beginFill(0x00ff00)
        .drawRect(0, 0, width, height);

    app.stage.addChild(rect);

    // Stop application wait for load to finish
    app.stop();

    PIXI.loader.add('shader', 'shader.frag')
        .load(onLoaded);

    var simpleShader;
    var uniforms = {};
    uniforms.mouse = {
      type: 'v2',
      value: { x:0, y:0 }
    }
    
    uniforms.time = {
      type: 'f',
      value: 0
    }

    uniforms.resolution = {
      type: 'v2',
      value:{ x: width, y: height}
    }

    function onLoaded (loader,res) {
      // Create the new filter, arguments: (vertexShader, fragmentShader, uniforms)
      simpleShader = new PIXI.Filter(null, res.shader.data, uniforms);

      rect.filters = [simpleShader];
      app.start();

      // bind mouse to shader effects
      btnOne.onmousemove = function(evt) {
        // Get the mouse position
        mousePos = { x: evt.clientX, y: evt.clientY }
        // Assigning a new value lets Pixi know to update the uniform in the shader
        // But doing something like uniforms.mouse.x = 0, won't update in this current version of Pixi
        simpleShader.uniforms.mouse.value = mousePos;
      }

      // apply the filter
      rect.filters = [simpleShader];

      // Animate the filter
      app.ticker.add(function(delta) {
        simpleShader.uniforms.time.value += 0.1
      });
    }

 

I read the post about creating filters in v4, but to a beginner it's just confusing as I don't understand a lot of the terminology used. Anyone can (hint how to) fix this so I can continue my explorations programming shaders? :)

Need help with Color grading / Color LUT shader with Pixi

$
0
0

Hi there - I'm going down a rabbit hole trying to implement a color grading / LUT shader for PIXI.  Color grading is where you can you use a sprite as a lookup table to quickly transform one set of colors to another - this is handy for applying realtime contrast and color adjustments. I'm using this as a reference:

https://www.defold.com/tutorials/grading/ 

I've created a filter/shader using the code in the link above:

 

var ColorGradingShader = function(LUTSprite) {

  var my = this;
  
  var code = `
  precision lowp float;
  uniform vec4 filterArea;

  varying vec2 vTextureCoord;
  uniform sampler2D uSampler;
  uniform sampler2D lut;

  #define MAXCOLOR 15.0
  #define COLORS 16.0
  #define WIDTH 256.0
  #define HEIGHT 16.0
 

void main() {

    vec4 px = texture2D(uSampler, vTextureCoord.xy);

    float cell = px.b * MAXCOLOR;

    float cell_l = floor(cell); 
    float cell_h = ceil(cell);
    
    float half_px_x = 0.5 / WIDTH;
    float half_px_y = 0.5 / HEIGHT;
    float r_offset = half_px_x + px.r / COLORS * (MAXCOLOR / COLORS);
    float g_offset = half_px_y + px.g * (MAXCOLOR / COLORS);
    
    vec2 lut_pos_l = vec2(cell_l / COLORS + r_offset, g_offset); 
    vec2 lut_pos_h = vec2(cell_h / COLORS + r_offset, g_offset);

    vec4 graded_color_l = texture2D(lut, lut_pos_l); 
    vec4 graded_color_h = texture2D(lut, lut_pos_h);

    
    vec4 graded_color = mix(graded_color_l, graded_color_h, fract(cell));

    gl_FragColor = graded_color;

}

`;
  
  PIXI.Filter.call(my, null, code);    

  my.uniforms.lut = LUTSprite.texture;
    
}

ColorGradingShader.prototype = Object.create(PIXI.Filter.prototype);
ColorGradingShader.prototype.constructor = ColorGradingShader;
  
export default ColorGradingShader;

 

I then add this to my top level container:

//relevant code from a wrapping class

this.colorGradingSprite = new PIXI.Sprite.fromImage('/img/lut16.png');

this.pixiContainer.filters = [
	this.colorGradingFilter
];

 

When using any LUT image, including the default without any color adjustments:

lut16.png.cc3d04f5f2c7df98c6013ebb8da3d4a2.png

 

 I go from this:

image.thumb.png.1a282aa03ab562d1ee6d391e78095d07.png

 

to this:

 

image.thumb.png.bbc93fe2eab2a6efd0c177fce3b9f32b.png

 

I'm assuming there are some adjustments necessary to either the shader code, or how the lut sprite itself is being loaded - I have no clue..

Any help would be greatly appreciated!

 

And for those curious, here's my end goal:

image.thumb.png.af046049a41ae4f48dfa76db4432ee78.png

 

Thanks,

Sean

[PIXI] Changing sprite textures

$
0
0

Hello!

 

Could any experienced Pixi users out there please tell me if what I'm doing is really bad?

I'm changing sprite textures using some code that looks a bit like this:

var section = new PIXI.Rectangle(  sourceX, sourceY, sprite._sourceWidth, sprite._sourceHeight);sprite.texture = new PIXI.Texture(sprite._baseTexture, section);

`_baseTexture`, `_sourceWidth` and `_sourceHeight` are all what you think they are.

 

Is this OK or am I entering some kind of garbage collection death-spiral that I don't know about?

Is there a better way or more "best-practice" way to change sprite textures? 

 

Also, I'm getting a slight flicker when the texture changes using the WebGL renderer. The canvas renderer is fine... I don't know if this is a Pixi bug or because I'm doing something really wrong?

 

 

 

 

 


Renderer is stretching to canvas dimensions

$
0
0

Hi for some reason the renderer is stretching  and squeezing to the canvas dimensions how do I prevent that and maintain the aspect ratio? See image below. The green square is suppose to be 50x50

streatch2.jpg

How to draw gradient color

$
0
0

HI:

i want to draw gradient color,but found draw gradient color of text,can not draw gradient color of other shape.How to draw gradient color of rectangle.

BitmapText (children/character anchors)

$
0
0

Hi all, was just wondering if there was anyway of changing the anchor of the BitmapText child sprites (character sprites) without messing with the kerning?

I've successfully got the characters animating with tweenmax, but for a rotation jiggle etc would be better from the center point!  Any tips greatly appreciated :)

Help to create a curved path

$
0
0

i need help with a game i'm creating. I need a platform which has a curved path and the player moves along the path created. I have created a path using Bezier Interpolation which creates a path using random points in a range. The issue is that i can only create the outline of the path and i need to fill the area under the curve so that it looks like a solid platform.  

Capture.PNG

Control resolution of pixi texture

$
0
0

Hi,

I am using pixi to display a texture that consists of alternating black and white rows of pixels. Unfortunately, pixi doesn't show these as black and white, but rather shows grey wave-like patterns that look like there is a lot of aliasing happening. That would make sense if the size of the texture did not match the size of the pixi view on which it is shown. Yet in both cases, width and height are 256. An alternative explanation for this could also be that pixi is attempting some form of pixel interpolation, yet my application is created with roundPixels=true and resolution=1. Where am I going wrong here?

Thank you,

ifru

Antialiased Circle

$
0
0

Hi everyone,

 

I'm using the Graphics stuff from the dev version of Pixi.js. I can draw a circle by doing this:

var graphics = new PIXI.Graphics();graphics.lineStyle ( 2 , 0x000000,  1);graphics.beginFill(this.colour);graphics.drawCircle(this.position[0], this.position[1], this.radius);

Ut73Tlq.png

 

But I was wondering if it is possible to draw it with antialiasing? I note it looks like the webgl contexts are created with {antialias:true} by Pixi. Do I need to make a PNG of a circle? That's less ideal for changing the colours.

 

Thanks,

Matt

 

extract image array from video

$
0
0

I have an mp4 video file (H264 encoded).

I want to create a PIXI.extras.AnimatedSprite from this video to be able not lagging reversed animation play;

If I splice this video to image sequence the size becoming huge (about 8Mb vs 500kb of mp4).

I want to load low size mp4 file and extract image array from it to create an Animated Sprite.

Reverse playing directly from <video> by changing video.currentTime is lagging. I want to create something like hover/unhover animation.


How to prevent zooming with browser?

$
0
0

Zooming with the browser seems to affect the size of the game.

This is my code here:

window.onresize = function (event) {
  var w = window.innerWidth;
  var h = window.innerHeight;
  renderer.view.style.width = w + "px";
  renderer.view.style.height = h + "px";
  renderer.resize(w, h);
}

How do I make it so regardless of how much the user is zoomed in their browser, the values w and h shouldn't change? (If the user resizes their window, it should change though)

Parallax scroller very much slows down on the phone

$
0
0

Hi, 

Why parallax scroller very much brakes on the phone (samsung a3 2016), in 2 - 3 minutes after the application launch?

PIXI.particles.ParticleContainer children particle hitAreas don't seem to follow the particles as they move

$
0
0

Greetings!

I'm currently playing around with PIXI.particles.ParticleContainer and am having a blast. What an awesome container!

I'm writing because I'm having a peculiar issue regarding mouse events and the particles inside the ParticleContainer. Specifically, I create the ParticleContainer, add sprites to it via PIXI.Sprite.fromImage and then bind mouse down events to each sprite and specify a hit area for the sprite as well. That works! Specifically, it works if I add the sprites to the ParticleContainer and don't specify a position, and all the sprites show up in the top left corner of the ParticleContainer. 

However if I move the sprites around in the container by adjusting the sprite's x,y values, the hit area remains in the in the top left corner and I can still trigger the mouse event there, but that's clearly not the intent.

I had guessed that the hit area would follow the sprites as they move around the container. Is this true?

I'm posting below a section of my code to help explain. Thank you to any PIXI wizards who might have insight here.

// Create the graph container
this.graphContainer = new PIXI.particles.ParticleContainer(
	numNodes,
	{
		scale: true,
		position: true,
		rotation: false,
		uvs: false,
		alpha: false
	}
);
this.graphContainer.hitArea = new PIXI.Rectangle(0, 0, 1000, 1000);
this.graphContainer.interactive = true;
this.graphContainer.interactiveChildren = true;

// Create the graph nodes
for (var i=0; i<numNodes; i++) {
	var x = graphData['nodes'][i]['x'];
	var y = graphData['nodes'][i]['y'];
	var node = new Node(this.top, null, x, y);
	this.nodes.push(node);
	this.graphContainer.addChild(node.getSprite());
}


class Node {

	constructor(top, type, x, y) {
		this.top = top;
		this.initPosition = {
			'x': x,
			'y': y
		};
		this.createSprite();
	}

	createSprite() {
		this.sprite = new PIXI.Sprite.fromImage('images/bcat.png');
		this.sprite.hitArea = new PIXI.Rectangle(0, 0, 100, 100);
		this.sprite.interactive = true;
		this.sprite.buttonMode = true;
		this.sprite.on('mousedown', (event) => {
			console.log('sprite event');
		});
		this.sprite.anchor.set(0.5);
		this.sprite.x = this.initPosition['x'];
		this.sprite.y = this.initPosition['y'];
	}

	getSprite() { return this.sprite; }

}

 

PIXI.TextStyle gradient stroke and pattern fillStyle

$
0
0

Hi,

I just want to ask if PIXI developers going to support pattern fill style and gradient/pattern strokeStyle.

Canvas API supports it.

context.strokeStyle=color|gradient|pattern;

context.fillStyle=color|gradient|pattern;

also multi stroke will be nice to have.

Maybe somebody can recommend me a lib with such text effects for PIXI

 

Virtual Container

$
0
0

Container and DisplayObject do not have their own size, its depends of its children, so If you add a Child and use anchor  property and others properties related with size it will not work.

What would be the best practice to do a simple layout like HEAD, BODY and FOOT? where I can define and limit the size of each "area" and all their children?

I thinking in create a new class that inherit Container and overwrite the width and height properties to be static but I'm not sure it will be considered in the anchor logic.

Any advice?, here an example how it does not work https://jsfiddle.net/fyt7zhvm/1/

Viewing all 3979 articles
Browse latest View live


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