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

Why Pixi.js ?

$
0
0

Hello everyone,

I'm a French Student in an Engineering school and i need to find the best way to do some animation in HTML5.
It seems there's three principal tools : Canvas, SVG and WebGL.
According to my recent research, Canvas is more for dynamic animation, if i need to refresh a lot of sprites, etc etc... ,SVG more for graphics, charts and pre-programmed animations and WebGL for 3D.
(Tell me if i'm wrong, because i feel like Canvas and SVG can do SAME, i can't see a real difference except about performance)

I saw there's a lot of library for Canvas(Pixi.js, Fabric.js, Easel.js...).
But what's the "real" difference between them ? Is there a benchmark for that ? Is there a list of features of Pixi.js for example ?
I search something concrete to compare theses libraries.

If someone could answer that :)
Sorry for my English,

Ytyse


How to remove MovieClip textures from TextureCache?

$
0
0

Hey, I'm looking for a way to clean up a Loader instance (and its content). I saw that I need to remove textures from the cache (maybe I need to do more things?), so I did (Haxe code) :

var cache = pixi.core.utils.Utils.TextureCache;

for (resource in Reflect.fields(loader.resources)) {

	var url = Reflect.field(loader.resources, resource).url;
	var texture = Reflect.field(cache, url);

	if (texture != null)
		pixi.core.textures.Texture.removeTextureFromCache(url);
}

It removes many textures, but if I enumerate my TextureCache content later, each frame of the sprite sheet is still there. Is there any way to do it via the spritesheet url ?

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.

 

Pixi + Custom Cursor + Disappearing Cursors

$
0
0

Hi

I'm wondering whether there is an intended way of replacing the cursor with an image using Pixi

Some ideas I have:

1) Would be using CSS to replace the cursor, I also see discussions related to a .defaultCursor property from 2013 that changes the cursor for specific sprites, even without any Pixi features that I don't know of, cursor could be changed with CSS on hover in/out etc.

2) Would be hiding the cursor and drawing it manually

One issue I'm facing on OSX, without any cursor modifications is a disappearing cursor, when I move around with WASD, the cursor disappears, what's bad is that this is not specific to Pixi or Gaming or the Browser, it happens everywhere, probably a system thing, so (2) seems like a good option - yet - if frames drop below 60 fps, it might give cancer to the player (Just came across this: http://stackoverflow.com/a/3899005/914546 - so (1) + (2) might be possible too)

Textures loading slowly when first added

$
0
0

Hello!

I have an object ("subclass" of PIXI.Sprite) whose texture I want to change at every frame, to create an animation. To do this, I use PIXI.loader.add and set up the object with a reference to the list of textures that it will use, and then change the texture property in the update loop:

function Effect(textureUrls) {
  this.urls = textureUrls;
  PIXI.Sprite.call(this, PIXI.loader.resources[this.urls[0]].texture);
  // ...
}

Effect.prototype.update = function(delta) {
  // ...
  var url = this.urls[this.frameIndex];

  this.texture = PIXI.loader.resources[url].texture;
}

My problem is that the framerate drops drastically during the first run through the animation, and on subsequent runs it goes smoothly. Any ideas on how to fix this? Is there a more efficient way of changing the texture than just setting the texture property? Due to other constraints in the project using a Texture Atlas is sadly not an option.

Using PIXI as a 'view'

$
0
0

Hi!

We are working on a small game, and we are trying to do so while maintaining a clean architecture, and clean code. We are also keeping up a high test coverage.
We don't want to completely rely on PIXI, we want it as a module to use it as a renderer, and we are trying to make it interchangeable any time.
So we maintain our own state tree with positions, velocities etc, because storing these are really the responsibilities of the business logic.

If PIXI had just a render method, like canvas has, it would be easy to just render everything in every frame based on our own state-tree.
But this is not the case, because PIXI forces us to store all the data (rotation, alpha, positions, anchors etc...) inside PIXI stages/sprites/containers, which totally messes up the principles of just using it as a 'view', and not a controller with responsibilities.
The question is: how can we cleanly separate PIXI, and really only use it as a renderer.
I hope you can help us, because there are no other libraries with this much cool features.

Thank you for your time, I'm waiting for your answers.

Getting original texture in between the filters as a uniform for the next filter

$
0
0

Hi there guys.

Say I want to make a filter that does something to original texture after it was blurred with Blur filter. Here's the PIXI blur filter:

BlurFilter.prototype.applyFilter = function (renderer, input, output)
{
    var renderTarget = renderer.filterManager.getRenderTarget(true);

    this.blurXFilter.applyFilter(renderer, input, renderTarget);
    this.blurYFilter.applyFilter(renderer, renderTarget, output);

    renderer.filterManager.returnRenderTarget(renderTarget);
};

Is there a way for me to store original input texture and use it as a uniform for my filter, kinda like that:

this.myFilter.originalTexture = input.texture;

this.blurXFilter.applyFilter(renderer, input, renderTarget);
this.blurYFilter.applyFilter(renderer, renderTarget, renderTargetTemp);

this.myFilter.applyFilter(renderer, renderTargetTemp, output);

I tried getting input.texture however input.texture is an empty WebGLTexture object at that point.

Filters that require a margin

$
0
0

I've written a simple outline shader that adds a single pixel border around a sprite. It works well, except because sprite textures are commonly cropped, the outline is missing at the edges of the image. I've included a blown up image to show you what I mean. See how the border is missing at the tops of the ears and at the extremities of the limbs?

What's the common way of dealing with shaders (like outline, blur, glow, etc.) that go over the edge of a cropped texture? Is there an easy way of adding a transparent margin around a texture? Or do I need to write a vertex shader to expand the size? I'm a little new to this, so I'd be grateful to learn of any solutions people might have.

Screen Shot 2016-06-10 at 15.38.06.png


How to Disable Font Antialiasing

$
0
0

I have this set in CSS to force pixellized images:

canvas, img { /* makes a change, noticeable [28/05/16] */
	image-rendering: optimizeSpeed;
	image-rendering: -moz-crisp-edges;
	image-rendering: -webkit-optimize-contrast;
	image-rendering: optimize-contrast;
	image-rendering: pixelated;
	-ms-interpolation-mode: nearest-neighbor;
}

I've tried this for fonts:

font-smooth: never;
	-webkit-font-smoothing : none;

It doesn't work

This is my renderer:

renderer = new PIXI.autoDetectRenderer(width,height,{antialias: false, transparent: false});

Yet from my experience antialias:false doesn't do much

Pixi V4 by the way

Any ideas how to improve the font rendering?

As it is, even at 36px, the text is awful, and I want it at 12px, at 12px, it's enough to make someone puke

awfultext.png

Pixi-canvas: pixi in a context 2d API

$
0
0

Hello everyone, 

I'm working on a little project that I named Pixi-Canvas. The idea is to wrap the Pixi renderer in an API that's similar to the 2d canvas API. This allows you to use functions such as context.drawImage, context.fillRect, context.save, context.rotate etc. like you would with canvas.getContext("2d")!  If you're already using Pixi or Phaser, then obviously this is not useful to you. The project is very similar to webgl-2d (if anyone remembers that), except this uses Pixi as the underlying renderer.

You can find this and more info here https://github.com/LuckyKat/pixi-canvas. Please check it out!

Motivation
While Pixi is the best and fastest renderer out there, I found that Pixi introduces a lot of structures that forces you to work in a certain way. I feel like it's half a game engine already! For my own game engine, I wanted to introduce my own entity-component system, parent-child relations and get in between the render calls per sprite. I felt that Pixi makes that pretty difficult! Working with the 2d canvas API in that sense is much easier, so I wrote a wrapper that could draw pixi sprites like you call context.drawImage. I decided to share this method and write a library that's easy to use.

Performance / difference with Pixi
Using Pixi-Canvas will definitely be slower than using Pixi normally. To test and compare the performance, I replicated the Pixi bunnymark.
On my Surface Pro 4 i5, the amount of bunnies I could spawn before hitting 30 fps:

Canvas 2d: ~4000 bunnies
Pixi-Canvas: ~30.000 bunnies
Pixi: ~55.000 bunnies

Note that this seems to differ a lot per device! I tried this on a Mac Mini the other day and Pixi-Canvas performance was a mere 5000 bunnies. So please give this a try on your own computer and let me know what your performance is. For comparison's sake, I copied Pixi's original bunnymark and turned off the ParticleContainer. ParticleContainers are much faster, but very limited in functionality, so it would be an unfair comparison. I uploaded the bunnymarks here (If anyone from goodboydigital is not ok with this, let me know and I'll take it down):
Pixi-Canvas: http://www.heigames.com/html5/bunnymark
Pixi original without particlecontainers: http://www.heigames.com/html5/pixibunnymark

I've tried to make Pixi-Canvas as optimal as possible of course. Under the hood, it does not use Pixi as you would normally. I'd love to know any tips that could make Pixi-Canvas faster!

trouble with dynamic text

$
0
0

Hi

I'm a newbie with pixi and am really enjoying it, I am creating a simple game but I cannot get the scoreboard to update dynamicaly, I can see the score increase in my console.log(score) but the number on screen remains at number 1. I have looked at online and at the manual and have tried .content but to no avail, what am I doing wrong ? I losing my hair

Below is my basic script :

var Container = PIXI.Container,
    autoDetectRenderer = PIXI.autoDetectRenderer,
    Graphics = PIXI.Graphics,
    Sprite = PIXI.Sprite,
    MovieClip = PIXI.extras.MovieClip,
    TilingSprite = PIXI.extras.TilingSprite,
    loader = PIXI.loader,
    resources = PIXI.loader.resources,
    Text = PIXI.Text;
    TextureCache = PIXI.utils.TextureCache,
    Texture = PIXI.Texture;

//Create a Pixi stage and renderer
var stage = new Container(),
    renderer = autoDetectRenderer(256, 256);
    document.body.appendChild(renderer.view);

//Scale the canvas to the maximum window size
var scale = scaleToWindow(renderer.view);

//Set the initial game state
var state = play;

//load resources
loader.add("images/player.png")
      .load(setup);

//Define any variables that might be used in more than one function
var gameScene = undefined, // container
    state = undefined;
    score =1;
    message = undefined;

function setup() {

  gameScene = new Container();
  stage.addChild(gameScene);
 
  message = new Text(score, {fill:"white"});
  gameScene.addChild(message);
 
 state = play;
  //Start the game loop
  gameLoop();
}

function gameLoop() {

  //Loop this function 60 times per second
  requestAnimationFrame(gameLoop);

  //Run the current state
  state();

  //Render the stage
  renderer.render(stage);
}

function play()
{   
    score++;  
    message.content = score;
    console.log(score);
}

Thanks in advance to anyone who can help me

Eric

How to move the sprite to the top?

$
0
0

Hi Guys,

 

   Is there a way to specify that sprite should go on top (similar to the way its done in phaser)?   I need to have multiple draggable sprites.   Currently the last one drawn is always on top.  So when you are dragging sprites, they will be dragged under the sprites that have been drawn later.

 

  I know it can be easily done by just clearing and redrawing the sprite every tick but it would make it much easier if there was an API to bring it to top layer on mousedown.

 

 

PS:  I know its two dimensional pixel grid(this seems to be common answer to these type of questions).. just talking about APIs here.

 

Pixi and Anchor positioning

$
0
0

Out of curiosity, how does everyone deal with positioning a object in pixi when the anchor is changed from 0 to something else?

pixi, atlas and spine destroy

$
0
0

Hi everybody,

I would like to know how to unload a texture atlas (created with TexturePacker) and a spine file (created with Spine). I have loaded them directly using something like

PIXI.loader
            .add(filename)
            .load(callback);

But I cannot see any destroy method like the texture's destroy method. I have noticed that the loader has a "_image" resource associated with the json file and also some texture (and also something else) associated with the spine file. Should I write a destroy method by myself or is there a "standard" way to do this?

I need to clear these resource types in order to free the GL memory.

Thanks!

generateTexture (v4)

$
0
0

I am trying to set a mask up, with generateTexture. The only problem I'm having is the placement of the sprite / container.

From what I understand generateTexture should take sprite or container position into account, right? If not, then I'm wondering what are the alternatives? If it should, then I'm wondering what I'm doing wrong?

There is a plunkr of it here (https://plnkr.co/edit/HU9YwhqBiRfG5J1mILxG?p=preview). It should work correctly, but it might be difficult to notice the mask, but you can notice it when you drag the map around.


Changing textures/skin in Pixi Spine

$
0
0

Hi all,

I'm working on an avatarbuilder and would like to use Spine for the animations. The avatar is made up of several parts (head, body, arms etc) that can be changed in order to get the desired combination. Now, I've been looking at using skins, but I'm not sure if I'm going the right direction. Since it's not a complete skin that needs to be swapped, but just a part of it.

The avatarbuilder will be made in Haxe using Pixi and Spine.

My main questions are:

1) Would it be possible to use skins in order to only change the head, or the body for instance?

2) Am I moving in the right direction using the skin feature of Spine?

 

Thanks in advance!

Maarten

About pixiFLIP

Multiline BitmapText with maxWidth issue

$
0
0

Hi.

I'm try to use BitmapText with pixi v.3.0.9 to display multiline text and I have some problems here. Just an example:
When I use just \n symbols to word wrap it works correctly:

    _bitmapFontText = new PIXI.extras.BitmapText("12\n 34\n 56\n 78\n 90\n 21\n 43\n 65\n 87\n 09", { font: '35px Desyrel', align: 'right' });
    _bitmapFontText.updateText();

When I use just maxWidth it works correctly too:

    _bitmapFontText = new PIXI.extras.BitmapText("12 34 56 78 90 21 43 65 87 09", { font: '35px Desyrel', align: 'right' });
    _bitmapFontText.maxWidth = 30;
    _bitmapFontText.updateText();

But when I've mix them.

    _bitmapFontText = new PIXI.extras.BitmapText("12\n 34\n 56\n 78\n 90\n 21\n 43\n 65\n 87\n 09", { font: '35px Desyrel', align: 'right' });
    _bitmapFontText.maxWidth = 30;
    _bitmapFontText.updateText();

The result will be so strange. Some of chars become duplicated (screenshot attached).
Mixed variant it's what I really need to have, because text which I'll set in real application could contains any number of \n symbols, but it should be placed just in specific area (which could be limited with maxWidth) 

wordwrapissue.png

Full screen background image

$
0
0

I am trying to achieve a similar design as this site using pixi-

 

http://www.spaceneedle.com/home/

 

 

However I am having trouble even finding out how to make a full page texture. Any image I use won't stretch to match the viewport. I have tried setting-

 

this.sprite.texture.width = viewPort.width;

 

or 

 

this.sprite.width = viewPort.width;

 

However there is always blank space on the right hand side? Any guidance would be greatly appreciated.

 

baaY9NQ.jpg

Tip: Use PIXI.SCALE_MODES.NEAREST for tiles and sprites, to prevent gaps and imperfections

$
0
0

So ever since I started game programming with PIXI, a soft issue of mine was gaps between tiles and upper shadows on sprite's (the shadow of an upper sprite frame showing up in the lower sprite frame)

This happened when I scaled the map/stage to 2/3 - my assumption was that, since I scale Integer and not Float, like 1.5 or sth, the scaling should have been perfect

But turns out it doesn't have to be, but with PIXI.SCALE_MODES.NEAREST it is perfect!

This is how I currently change the mode: PIXI.utils.BaseTextureCache[file].scaleMode=PIXI.SCALE_MODES.NEAREST - works, but it might not be the intended way of doing it

Viewing all 3980 articles
Browse latest View live


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