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

help with device orientation and canvas resize

$
0
0

Hello everyone, I'm trying to make a resizable canvas following this guides I found in this forum https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html. I'm sure this topic has been discussed plenty of times and I have spent some time searching for some info I could use but with no luck (most of the replies make use of window.innerWidth/innerHeight). The thing is that It seems ok when displayed on a desktop or a mobile device in portrait mode, but when I change to landscape and reload the page nothing is shown on the canvas. As far as I know when it rotates, width becomes greater than height and coordinate system does not change at all, so I don't know what I'm missing :( (something related to mobile resolutions and ppi maybe?)

I'm fairly new to html/css/js and I'm certain that the issue is related to my poor knowledge with some concepts. Here is the code anyway, any help or directions would be very much appreciated.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no"/>
    <title>My PIXI App</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.5.6/pixi.min.js"></script>
    </script>
</head>
<body>
</body>
</html>
* {
  padding: 0;
  margin: 0;
}

html {
  width: 100%;
  height: 100%;
}

body {
  background-color: lightslategrey;
}

canvas {
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
}
const width = 512;
const height = 512;

const appOptions = {  
  width: width,
  height: height,
  resolution: window.devicePixelRatio,
  roundPixels: true,
  transparent: false,
  backgroundColor: 0x555555,
};

const app = new PIXI.Application(appOptions);
document.body.appendChild(app.view);

coolResize();
app.ticker.add(coolResize);

drawSquare();
drawSquare(app.view.width / 2 - 25, app.view.height / 2 - 25);


function coolResize() {  
  const multiplier = app.renderer.options.resolution || 1;
  const clientWidth = Math.floor(app.view.clientWidth * multiplier);
  const clientHeight = Math.floor(app.view.clientHeight * multiplier);

  if (app.view.width !== clientWidth || app.view.height !== clientHeight) {
    app.view.width = clientWidth;
    app.view.height = clientHeight;    
        
    return true;
  }

  return false;
}

function drawSquare(x = 0, y = 0) {
  const graphics = new PIXI.Graphics();
  graphics.lineStyle(2, 0xFF00FF, 1);
  graphics.beginFill(0xFF00BB, 0.25);
  graphics.drawRoundedRect(x, y, 50, 50, 10);
  graphics.endFill();

  app.stage.addChild(graphics);
}

I've created a fiddle just in case it could be of any help:

https://jsfiddle.net/pmyzLk35/

 

Thank you so much and I'm sorry for wasting your time.

PS. Btw I don't know why should I resize first and then add the resize function to the ticker, shouldn't adding to the app.ticker be enough? I tried it but does not lead to the same result. I'll take a look to the docs later I guess.


Pixi.js + TypeScript boilerplate

$
0
0

After a couple of days working with Pixi.js, I've built up a simple boiler plate for the TypeScript language I'm glad to share: https://github.com/yahiko00/PixiProject

The game loop with a FPS meter is already implemented.

This boiler plate supports source maps, incremental builds, unit tests and browser auto-refresh.

Maybe this could be helpful.

Feel free to comment. There is certainly a room for improvement.

Cheers! :)

How to resize windows anytime and access mouse position directly in pixi.js?

$
0
0

1.  How to resize the window at any time when I change my window size. Something weird will occur in my app now like the image below.(the right size should be black)

2. How can I directly access mouse local position without listening to an event. I want to deliver my mouse local position to the server even if the mouse doesn't move at all.

Thx a lot!!

Screen Shot 2017-12-10 at 1.06.00 AM.png

Screen Shot 2017-12-10 at 1.06.03 AM.png

Pixi + Custom caching

$
0
0

Hey,

I am completely lost in my game blobber.io. I debugged already a lot of bugs but this one I have been working on for the last 14 days and I am unable to find it. The original frontend developer created some custom caching before sending the data to PIXI to show. 

Before restarting the game or being respawned automatically the game is cleaned from cache but sometimes these objects are still drawn. More visible in underneath link. I am completely blocked by this and would so much appreciate if someone could help be further. 

https://www.dropbox.com/s/mv2elk7zpfk1sl3/IMG_8930.m4v?dl=0

PIXI Filter - access non-premultiplied alpha

$
0
0

I've been working with PIXI filters recently.

If I apply the filter to a sprite with alpha, I've noticed that somewhere along the line the alpha gets premultiplied.

For example, I have a test texture with a pixel saved as [255, 255, 255, 128].

When I sample the texture, in a filter Instead of [1.0, 1.0, 1.0, 0.5] the result is [0.5, 0.5, 0.5, 0.5].

How can I turn off this premultiplying behaviour? I've tried 'transparent: false' and 'transparent: "notMultiplied" ' in the webGL renderer settings, but neither of those seemed to make any difference?

Container background color without graphics?

$
0
0

Hello,

 

Is it possible to color the background of a container without using graphics of any sort? Some kind of 'native' background color property or so?

 

Thank you.

Kind regards,

Fennek

proper canvas resizing method

$
0
0

Guys, sorry for bothering with this question, I found a few answers to this problem, but im still not able to get it to work.

I have made a complex app in Pixi, but now Im fighting with a trivial problem, how to properly set up HTML file and resize function to let my canvas resize to actual window size.

Now my HTML file contains one div:

<div id="floorplanner" class="pixi"></div>

here is css file:

body {
    position: absolute;
    height:100%;
    width:100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

canvas {
    padding: 0;
    margin: 0;
}

.pixi {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

I append canvas to this div using:

document.getElementById("floorplanner").appendChild(renderer.view);

and finally I have attached function scaleToWindow(renderer.view, "#CCCCCC");

(function source bellow) to window "resize" event:

  //Center and scale the game engine inside the HTML page 
  function scaleToWindow(canvas, backgroundColor) {

    backgroundColor = backgroundColor || "#2C3539";
    var scaleX, scaleY, scale, center;
	
	//1. Scale the canvas to the correct size
    scaleX = window.innerWidth / canvas.width;
    scaleY = window.innerHeight / canvas.height;

    //Scale the canvas based on whichever value is less: `scaleX` or `scaleY`
    scale = Math.min(scaleX, scaleY);
    canvas.style.transformOrigin = "0 0";
    canvas.style.transform = "scale(" + scale + ")";

    //3. Remove any padding from the canvas  and body and set the canvas
    //display style to "block"
    canvas.style.paddingLeft = 0;
    canvas.style.paddingRight = 0;
    canvas.style.paddingTop = 0;
    canvas.style.paddingBottom = 0;
    canvas.style.display = "block";
    
    //4. Set the color of the HTML body background
    document.body.style.backgroundColor = backgroundColor;    

    //Fix some quirkiness in scaling for Safari
    var ua = navigator.userAgent.toLowerCase(); 
    if (ua.indexOf("safari") != -1) { 
      if (ua.indexOf("chrome") > -1) {
        // Chrome
      } else {
        // Safari
        canvas.style.maxHeight = "100%";
        canvas.style.minHeight = "100%";
      }
    }

    return scale;

  };

It works somehow (buggy), but according to this topic 

I should use renderer.resize(window.innerWidth, window.innerHeight); metod, but im not able to iplement it. Can anybody please help or provide a few rows simple sample of proper canvas+HTML setting up?

I also found this article http://www.williammalone.com/articles/html5-game-scaling/, but the William uses plain image in showcase, but I dont know, how to change his image to my canvas to get it to work...or simply how to implement it...

Odd issue with resizing renderer - innerWidth and innerHeight not returning the correct values

$
0
0

My app uses a renderer that spans the entire height and width of the browser and is completely responsive to its size. On desktop the renderer resizes fine as I resize the browser. I can also open up the dev tools in Chrome and switch to responsive view and the renderer will resize correctly. However, once I emulate a mobile device such as the iPhone 6s (or check it using a physical one) the values returned by window.innerHeight and window.innerWidth come back incorrect. Height will sometimes be tripled, for example. Even stranger, on page load when emulating the iPhone 6s in landscape mode, everything looks fine. Once I change the orientation to portrait or load the page on portrait, it's broken!

Here's how I initialize the canvas:

stage = new Container();
renderer = new PIXI.CanvasRenderer({
    transparent: true,
    resolution: 1
});
PIXICANVAS.appendChild(renderer.view);

renderer.view.style.position = 'absolute';
renderer.view.style.display = 'block';
renderer.autoResize = true;
WIDTH = window.innerWidth;
HEIGHT = window.innerHeight;
renderer.resize(WIDTH, HEIGHT);

Here's the resize event:

var events = {
    getScreenParams: function() {
        WIDTH = window.innerWidth;
        HEIGHT = window.innerHeight;
        HEIGHT > WIDTH ?
            orientationIsPortrait = true :
            orientationIsPortrait = false;
    },

    windowResize: function() {
        setTimeout(function() {
            events.getScreenParams();
            renderer.resize(WIDTH, HEIGHT);
            events.getBreakpoints();
            events.updateAllSprites();
        }, 250);
    },

    ...
}

Here's the listener:

window.addEventListener('resize', debounce(events.windowResize, 50), false);

Anyone else experience this issue?

 

 


PIXI 4.6+ way of cutting shapes using other shapes?

$
0
0

I've been reading a backlog of how to do this all the way back to when the recommendation was to use canvas. What is the new and modern way of accomplishing this? Let's say I have a rectangle that fills my screen and makes the game look like night time.. then I have a torch and I want to cut (or lighten) a circle out of the night rectangle.

I've tried drawing a circle using graphics and setting its colors to white, black, and alphas to 1.0 or 0, then adding it as a mask onto the rectangle -- this only seems to perform a regular mask operation (aka draw the night within the circle) but never the opposite (draw the nighttime everywhere but the circle). I know how to accomplish this via canvas or webgl, but it looks like this feature is already in pixi I'm just not sure how to do it!

Thanks for reading!

p.s. if the answer involves using a filter could you please reply with code.. im never sure which object exactly gets the filter added

EDIT: and will the new method work if calculated *every frame* ?

basic demo "Video" for HLS source

$
0
0

Hi, I am trying to draw HLS video stream over PIXI video texture on iOS safari browser (iOS 11.2) referring http://pixijs.io/examples/?v=v4.6.2#/basics/video.js  but not succeeded.

(Sorry for poor English as I am Japanese)

When I set mp4 video as source, the demo code worked over iPhone + mobile safari (OS: 11.2).

But when I set url of HLS (m3u8) and tapped play button, video did not drawn. 

I tried some change but not succeeded to play HLS stream over PIXI video texture.

Below is my code,  modified part of http://pixijs.io/examples/?v=v4.6.2#/basics/video.js .

...

function onPlayVideo() {

    // Don't need the button anymore
    button.destroy();

/// modify start

    // mp4
    // (1) mp4 OK : video/audio played (#fvlivedemo.gnzo.com is my own server)
    // var texture = PIXI.Texture.fromVideo('http://fvlivedemo.gnzo.com/testVideo.mp4');

    // (2) mp4 OK : video/audio played
    // var texture = PIXI.Texture.fromVideoUrl('http://fvlivedemo.gnzo.com/testVideo.mp4');

    // HLS
    // (3) Not work : when play button pressed, loading m3u8 not started. 
    //     #http://184.72 ... is effective m3u8 stream 
    // var texture = PIXI.Texture.fromVideo('http://184.72.239.149/vod/smil:BigBuckBunny.smil/playlist.m3u8'); 

    // (4) Not work : when play button pressed, loading m3u8 not started.
    // var texture = PIXI.Texture.fromVideoUrl('http://184.72.239.149/vod/smil:BigBuckBunny.smil/playlist.m3u8');

    // (5) Not work : when play button pressed, loading m3u8 started and audio play started. but video is not drawn on canvas. 
    let baseVideoTexture = PIXI.VideoBaseTexture.fromUrl({ src: 'http://184.72.239.149/vod/smil:BigBuckBunny.smil/playlist.m3u8', mime: 'application/vnd.apple.mpegurl' });
    var texture = PIXI.Texture.from(baseVideoTexture);

/// modify end

    // create a new Sprite using the video texture (yes it's that easy)
    var videoSprite = new PIXI.Sprite(texture);

...

Please help/guide me regarding right way/manner to play HLS stream over video texture of PIXI. (i.e. how to fix above code) 

entire HTML which I modified is attached (pixi_video_hls.html)

If more information needed for answer, let me know.

Thank you in advance.

pixi_video_hls.html

Dragonbones .json

$
0
0
Do you guys know how I can use a .json object exported from Dragonbones, with Phaser and/or Pixie? 
 
Is there a tutorial, a script an example to show us how it works? 
 
Thanks alot

Zooming a graphic/container/element on click

$
0
0

Hey everyone!

I am trying to achieve a zoom on an element using PIXI

I have currently a graphics rectangle (see first image) It is the child of my stage which is the main container being rendered. My main container is as big as the browser screen. 
On clicking the graphics element I want the stage to zoom in in a way that I get this output (see second image) 

As you can see on the desired output I want the rectangle to take up the whole container. I am confused with what pivots do I choose and what new positioning do I set to achieve this and till what point do I scale this?

Capture.PNG

Capture_Desire.png

The best practise of animation workflow

$
0
0

What is the best practise of animation workflow for Pixi.js?

It seems the best animation design tool is still Adobe Animate.

I just tried pixi-animate, pixi-flash, and PixiGAFPlayer.

 

So which one is the best you think?

 

Features I need:

  1. GUI keyframe editor
  2. Tween
  3. FrameScript
  4. Sound
  5. getChildByName

Games in PIXI producing a black/flickering screen on Huawei device

$
0
0

've been making a bunch of games using PIXI.js (version 3.0.6). However, none of the games work on my Huawei device (android version 5.0.1). Either the screen is completely black, or the screen flickers black, or the screen flickers black for a bit and then goes completely black.

After doing some searching online, I've found two possible solutions to what looks like the same problem (https://github.com/pixijs/pixi.js/issues/2721).

One solution that has been proposed is to change the shader precision value to mediump. However the attribute PIXI.PRECISION. or PIXI.settings.PRECISION does not seem to be available in the version 3 of PIXI.

The other solution proposed is to ad the following code before creating the renderer:

           PIXI.glCore.VertexArrayObject.FORCE_NATIVE = true;

However, to do this, I need glCore, and after reading some of the documentation (https://github.com/pixijs/pixi-gl-core), it seems like this is built to work with PIXI version 4.

Having said that, I don't even know if these solutions would actually fix the problem.

Anyway, any help would be much appreciated!

Using pixi-particles-editor with AnimateCC

$
0
0

Hi guys,

I am using AnimateCC to output canvas animations and would love to know how I would go about using the json file that is made available for download when using: http://pixijs.io/pixi-particles-editor/# . My objective is to simply create a particle emitter and then use it within my animation, but I have trouble connecting the dots. Ideally the Pixi json would need to be included in the published js file. Any tips on where that code would need to go exactly?

I added the pixi library as a global script to the Animate file, but was wondering if someone could walk me through the process of combining the power of AnimateCC with PIxi.js

Any tips are welcome! Thanks!


Pixi.js renderer not working

$
0
0

So basically I have a big project ongoing.
Instead of having nested constructors that passed down all the game data such as renderer, resources and so on, I decided in my Game.js file to make it static and then require that in every other file and directly get the required data through there.

It is quite a big project, so I am not going to include files, instead I'll be linking to my git repository.

The issue is that nothing gets rendered on the screen and no errors are shown at all. I've tried 2 different browsers aswell.

I've tried with both the CanvasRenderer and WebGLRenderer yet the same error still occurs.

 

And I've checked the PIXI Container that gets rendered, and it does contain children of other DisplayObjects.

 

https://github.com/marcus-sa/StormEngine/tree/dev/client

4urNnHZ.png

Bunny drag example with correct mouse offset

$
0
0

Hi,

 

disclaimer: pixi newb here.

 

I am working on an isometric example and as such want to be able to drag the background to move the scene.

Starting from the bunny example (#8) I noticed a behavior that isn't desirable for my particular case. Once you click on the bunny, the sprite jumps to center at your mouse cursor. It's barely noticeable because the bunnies are rather small, but once you tried this with larger sprites, it is pretty obvious:

http://jsfiddle.net/dirkk0/3B2DY/

 

I am not sure if this is the most elegant solutions (comments welcome) but the way I solved this was to introduce to new local variables in mousedown...

this.sx = this.data.getLocalPosition(bunny).x * bunny.scale.x;this.sy = this.data.getLocalPosition(bunny).y * bunny.scale.y;

...and to change the position with this offset in mousemove.

this.position.x = newPosition.x - this.sx;this.position.y = newPosition.y - this.sy;

Working example here:

http://jsfiddle.net/dirkk0/cXfpq/

 

Best,

  Dirk

Move stage pivot so that element is center

$
0
0

Hey everyone,

I want to center an element (in this case a graphics element) in the center of the screen. 

https://jsfiddle.net/user/adnanchang/fiddles/

As you can see from my code, I am changing the position of the graphics and bringing it to the center of the screen. I don't want that. I want to actually move the pivot/position of the stage in such a manner that the graphics then looks like it is to the center of the screen. Also, would it be possible to save the original position of the stage?

About fonts...

$
0
0

Hi!

I'm doing a thing in pixi (actually, in it's dart port (https://github.com/FedeOmoto/pixi) but that should be the same for the purpose of this question) and I'm using its text features (http://www.goodboydigital.com/text-updates/).

I understand that before rendering a text, you set the style in which to render it, and that the style includes many different things like color, align and font... What I don't get is: where do the fonts come from? In the provided example, they used 'Arial' font and I know for sure that you can use 'Snippet' font as well. Is there any list of all available fonts I can choose from? And will these fonts work the on every machine?

 

fixed physics update

$
0
0

Hi all, 

I am a bit confused on how should I procede if I want to have my game update the physics at 25hz.

So, clearifying myself, my scenario:

I have a game server that run updates 25 time per sec.

I need on my client ( Just trying out pixi ) to simulate the physics too because of lag ( dead reckoning, ecc. ecc. )

So, i tried out this, but that bunny looks so clumsy. ( it is the basic example )

What's the good way to get it done ?

var update_rate = 1000 / 25;
var update_time = 0;


// Listen for animate update
app.ticker.add(function(delta) {
    update_time += app.ticker.elapsedMS;
  
    if (update_time < update_rate)
      return;
    update_time -= update_rate;
  
    bunny.rotation += 0.1 * delta; // is that even corret to multiply with delta in this case ?
});

 

 

Viewing all 3978 articles
Browse latest View live


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