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

Wobbly pick-up effect

$
0
0

Disclaimer: I know this sounds nooby af, but I don't even know how it's called what I want and I do not search for a solution, I search for ideas.(:

Maybe you guys played Hearthstone, or any other card game. When you pick up cards from your hand, they do some wobbly fx (<- I'd appreciate to get to know how to call this shit.) because the card has some elastic physics to it.

My first idea to do this would be using pixi-projection with some easing to it. But then the question is what to apply with easing to let it look right and not completely fucked up?^^
I guess the scaling should to have some easing to it and the 4 corners need to "spread out" with different speeds?

The next thing I thought about where displacement maps. But tbh, I have no idea how this black magic works and how to apply it doing some animated stuff.

Please don't be like "oh you rookie..." - I know I am.
Please don't be like "heres code: ..." - I want to know what I'm doing pls.
Please be like "this is an interesting resource: <link to interesting resource>".

Love.👾


Game Engine, using Pixi.js, Typescript, gulp & webpack

$
0
0

Hi guys,

I am relatively new to game development, but I have to say I love it.

I want to start the development of a game of my own and I decided to try creating my own engine, mainly for the purpose of being part of the whole process. I think this will be the most appropriate way to completely understand everything that is going on behind the curtains. I picked Pixi.js as renderer and typescript as programming language. I will use webpack for bundling external modules and frameworks, and gulp for task runner.

I've done a lot of reading on the subject recently, but I could not find a tutorial, that is updated with the latest versions of the above, so I started my own.

With great help of different articles I found here, and all over google, I came up with the below:

https://github.com/idzhurov/pixijs-game-boilerplate

I am thinking of expanding this one up to a standalone game engine using pixi(I know, absurdly ambitious :D. but I will definitely try). At this point I am planning the creation of scene/scale handling, collision detection, asset loaders. Any opinion/advice/guideline will be greatly appreciated.

PS:

Big thanks go to @Ezelia for the above, as it is still relevant, and to @overthink for https://github.com/overthink/pixitest. Helped me a lot for my choice.

 

Efficient way to create many textured ropes of different lengths?

$
0
0

I have a horizontally tiling texture that I want to use to create flexible ropes in PIXI. I followed the same general path as is mentioned here, and it works, however I do have a slight worry. Every different length of rope in this case means another texture in image memory with size proportional to the rope length. I want to have a large number of ropes, all of different lengths. This feels quite expensive to me - is there a more efficient way to do this that doesn't involve baking a new texture for every rope length?

EexJOsd.png

Animate drawing along a bezier path

$
0
0

Hey,
I have some problems with drawing the animation using pixi-tween. I want to animate a drawing along the bezier path. I am basis on this example -> https://github.com/Nazariglez/pixi-tween/blob/master/examples/easing.html
 but my code still doesn’t work. Any idea where am I wrong?

That's the code:

var app = new PIXI.Application(1200, 800, {antialias: true});
document.body.appendChild(app.view);

var raf;
    function animate(){
      raf = window.requestAnimationFrame(animate);
      app.render(app.stage);
      PIXI.tweenManager.update();
    }
    function stop(){
      window.cancelAnimationFrame(raf);
    }
  
var path = new PIXI.tween.TweenPath();
  path.moveTo(0.4,0.4);
  path.bezierCurveTo(0.4,360.5,292.29,652.4,652.4,652.4);
  path.bezierCurveTo(87.5,65.4,105.9,47,105.9,24.89);
  path.closed = true;
  
var t = new PIXI.Graphics();
app.stage.addChild(t);

var tween = PIXI.tweenManager.createTween(t);
tween.on('update', function(delta){
 tween.path = path;
 tween.time = 13000;
 tween.easing = PIXI.tween.Easing.outBounce();
 tween.loop = true;
 tween.lineStyle(10, 0xff0000);
 tween.drawPath(path);
 tween.start();
});

 

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/

 

 

 

 

 

Pixi and React

$
0
0

I'm playing around with PIXI and React... I have a basic animation running from within a React component... the function that handles this gets called on componentDidMount()... the parent component passes down a prop called valueIsMatched... does anyone see any way that I can get the animation loop to console.log "value is matched" when the parent state changes to true?
 

Quote

componentDidMount() {
    this.pixiInit();
  }
  pixiInit = () => {
    var VELOCITY = 100;
    const stage = new PIXI.Container();
    const renderer = PIXI.autoDetectRenderer(
      500,
      400,
      {view : this.theCanvas}
    );
    const rectangle = new Rectangle();
    stage.addChild(rectangle);
    let lastTime = new Date().getTime();
    requestAnimationFrame(update);
    function update() {
      const currentTime = new Date().getTime();
      const delta = (currentTime-lastTime)/1000;
      rectangle.position.x -= VELOCITY*delta;
      if (valueIsMatched === true) {
        console.log('value is matched');
      }
      renderer.render(stage);
      requestAnimationFrame(update);
      lastTime = currentTime;
    }
  };



Also, I am aware of React-Pixi, but I was not able to get in running with latest React. 

A few questions about pixi.js on building agar.io

$
0
0

Recently I am building an io game like agar.io.

But I encounter 2 problems now.

First, after reading up some articles in this forum about the camera on pixi.js.I found the best way is to set pivot to the container. I try this and work greatly. But I just wonder can I create another container called camera to perform the functionality of camera instead of using app.stage as a map and camera at the same time?

Secondly, what is the best way to get my circle bigger when I eat a food? The only way I think of is using PIXI.Graphics to draw a new circle and replace the old one with it.But it seems time-consuming and stupid. Are there any better solutions?

Thx everyone!

Below is my test code on pixi.

import * as PIXI from 'pixi.js';
// SOME ALIAS
const Application = PIXI.Application;
const Graphics = PIXI.Graphics;
const Sprite = PIXI.Sprite;
const ObservablePoint = PIXI.ObservablePoint;
const Container = PIXI.Container;
const Point = PIXI.Point;

// CREATE A NEW PIXI APP
const appConfig = {width: window.innerWidth, height: window.innerHeight,antialias: true, view: document.querySelector('#root')};
const app = new Application(appConfig);
 
// CREATE NEW SPRITES
const spriteMove = Circle(0xffffff,30);
app.stage.addChild(spriteMove);
const spriteStop = Circle(0xe83a30,50);
app.stage.addChild(spriteStop);
 
// SET CAMERA
// FIXME CAN'T NOT BUILD A INDEPENDENT CAMERA MAYBE BECAUSE OF THE PIXI ORIGINAL DESIGN
const camera = new Container();
app.stage.position.set(app.screen.width/2,app.screen.height/2);
 
// ANIMATION
app.ticker.speed = 0.1;
app.ticker.add(()=>{
spriteMove.x += 0.5;
spriteMove.y += 0.5;
// GROW BIGGER
// app.stage.children[0] = Circle(0xfff,r++);
// IT DOES NOT ASSIGN REFERENCE SO IT HAS TO BE PUT IN ANIMATION LOOP
app.stage.pivot.copy(spriteMove.position);
})
 
// GRAPH FUCNTION
function Circle(c, r){
const g = new Graphics();
g.lineStyle();
g.beginFill(c);
g.drawCircle(0, 0, r);
g.endFill();
const s = new PIXI.Sprite(g.generateCanvasTexture());
s.anchor.set(0.5,0.5);
return s;
}
 

Ui testting tool for pixijs

$
0
0

Hi,

   I need some info on UI automation testing of pixijs webapp. We tried with Protractor & Katalon studio but couldn't able to detect the elements rendered by Pixijs .

Any help on which automation tool works with pixijs will be helpful. 

 

Thanks,

Deep


CacheAsBitmap and reuse

$
0
0

Hi all

Im working on a new slot prototype and had a bit of a thought about creating reelstrips to use for different animations, and just wanting a little advice on best approach.


Because I've had problems caching the spines as bitmaps for the reel drops had a different idea to it. 

At the moment I'm using spines for the icons, what I would like to do is have a function that generates a random strip (of any length passed of the icons - add the landing icons to the end of the strip - positioned the same as they would be in the reels, cache it as a bitmap and destroy the icons - then use the animated strip for the animation.

Thought to have the animated icons static and hidden in the reels.  Instead of animating them on the reel drops use the generated reel strips if that makes sense?  This way I can make a robust spin function that can work at different speeds loops etc?  Reason I would rather do it in game rather than manually via photoshop is I can reuse it for different icons, games can tweak and the strips would update to match?  Presume filters would run better as well with this approach rather than directly on spines?

To reuse presuming I would have to save out as a png using canvas to image - or would this idea be way too much overhead?  Also would the pngs then need to be readded to the pixi loader or would they be already accessible somewhere?  It wouldnt be run during the game, only at startup behind the scenes I think.

Just starting out with it now, so any advice greatly appreciated!

 

Recognising when a user is clicking below a particular sprite

$
0
0

I have a game, built using pixi.js, where I want to run some code every time the user presses below a certain sprite. I am handling the press event using hammer.js. The problem is that the y attribute of the sprite and the y attribute of the user’s touch event don’t match what I can see on my screen. As, an example, consider the code below:

if (touchPointer.clientY > this.children.marker1.position.y) {

console.log("******* Clicked Below the Line ********: ");} else{

console.log("******* Clicked Above the Line ********: ");}

The problem I have is that, when I click slightly above the sprite, the first section of code will run (which prints “Clicked Below the Sprit”), even though on the screen, I can clearly see the pointer is above the sprite. I am guessing, what’s going on is that the y positions for the pointer and the sprite are being calculated differently, but I don’t know how to go about ensuring they’re calculated consistently, so I can properly compare sprites against the pointer. After doing some research, I think the problem, more specifically, might be that I need to convert "screen coordinates" to "world cordinates". I'm not really familiar with the difference between "screen coordinates" and "world cordinates", but presumably the y position of the pointer is being calculated using "screen cordinates", and I need to convert these coordinates into "world cordinates", but I don't have any idea how to do this. Any suggestions?

Performance Issues with an interactive parallax demo. Fixable?

$
0
0

This little project I'm working on used this excellent proof of concept as a reference for creating a responsive, interactive parallax experience. Check it out to get a good idea of what's going on with my project.

My project is built and I'm currently going through and fixing cross-browser compatibility bugs. The problem I'm having is that I'm seeing significant FPS drops. On my 2 year old MBP I'm able to run it at a consistent 60fps on Chrome and Firefox but it gets a bit choppy in Safari. Alternatively, on an older windows 7 laptop it runs very slowly (~10 fps) on IE11 and FF but runs at 60fps on Chrome (btw, that laptop has an Intel HD 3000 integrated gpu and an i5-2450M cpu). So in this case it seems like it may be more browser-related than hardware.

It's also important to note that in my project I'm not Tweening the objects' animations as they move around the screen (I'm only using it when they are shown or hidden) however, the codepen demo above runs fine on the older windows 7 laptop but shows similar performance issues in Safari on my MBP. And more specifically with Safari, the performance improves as the size of the browser window decreases (even though the same number of images are being rendered and repositioned. In fact if I only render one image it's still choppy at larger screen sizes but smooth when it hits about 1200px wide).

Any thoughts on whether this could be further optimized? Is there any way I can make improvements to the animation system that would significantly improve the performance in these configurations?

By the way, in the attached script you'll see some working features commented out (such as the animated sprite). These had very little impact on the framerate but I've left them commented out anyway. Also, the performance improves as I remove objects but I don't see much of an improvement until about 80–85% of them are gone.

 

Edit:

Forgot to mention that I'm using Pixi 4.6.2

 

main.js

Create multiple rectangles of multiple sizes

$
0
0

I am currently creating a rectangle like so:

Quote

export function Rectangle(width, positionX, positionY) {
  let rectangle;
  rectangle = new PIXI.Graphics();
  rectangle.beginFill(0xFFFF00);
  rectangle.drawRect(0, 0, width, 10);
  rectangle.position.x = positionX;
  rectangle.position.y = positionY;
  return rectangle;
}

const rectangle = new Rectangle(100, 600, 300);
    stage.addChild(rectangle);

What I would like to be able to iterate through an array of objects that each contain width, positionX and positionY values, in order to be able to create / stage one group that contains all rectangles:

Quote

    let rectangle;
    rectanglesToRender.forEach((note, i) => {
      rectangle = new PIXI.Graphics();
      rectangle.beginFill(0xFFFF00);
      rectangle.drawRect(0, 0, rectangle.width, 10);
      rectangle.position.x = rectangle.positionX;
      rectangle.position.y = rectangle.positionY;
      stage.addChild(rectangle);
    });

I also need to be able to move the entire group of rectangles at a steady rate (something I'm already doing with the single rectangle) and I need to be able to do collision detection with each individual rectangle.

Any ideas?

detect collision with sprites in Container

$
0
0

I am creating the following container with multiple sprites:

 

Quote

    const rectangles = new PIXI.Container();
    const interactionManager = new PIXI.interaction.InteractionManager(stage, renderer.view);

    rectanglesToRender.forEach((rectangle, i) => {
      window['rectangle'+i] = new PIXI.Sprite(texture);
      window['rectangle'+i].width = note.width;
      window['rectangle'+i].position.x = rectangle.positionX;
      window['rectangle'+i].position.y = rectangle.positionY;
      window['rectangle'+i].interactive = true;
      window['rectangle'+i].hitArea = new PIXI.Rectangle(0, 0, 5, 400);
      rectangles.addChild(window['rectangle'+i]);
    });

    stage.addChild(rectangles);

And I am trying to figure out how to detect when any sprite has collided with a specific point on the stage:

 

Quote

    const update = () => {
      const currentTime = new Date().getTime();
      const delta = (currentTime-lastTime)/1000;
      rectangles.position.x -= VELOCITY*delta;
      // update rectangle position
      rectanglesBeginning = rectangles.position.x;
      rectanglesEnd = rectanglesBeginning + rectangles.width;

      // check if line is within rectangle
      const point = new PIXI.Point(0, 300);
      const hit = interactionManager.hitTest(point);
      console.log(hit);

      renderer.render(stage);
      requestAnimationFrame(update);
      lastTime = currentTime;
    };

    requestAnimationFrame(update);

  };

I've done a lot of Googling and a lot of experimentation, and I have not been able to figure it out.

Any help is all is very much appreciated.

Text Input?

$
0
0

What is the best way to make a Text Input? I've been researching for hours and trying so many things and can't seem to get a text input working at all.

When using a regular HTML text input, the textbox seems to have focus if I click on it, but typing inside of it does nothing. I assume this is due to Pixi taking all input? How can I stop this?

Better yet is there any Text Input that works directly inside Pixi? I seen some projects people created before for text input for Pixi, but those are extremely old and none of them work. I even tried to port them from Pixi v2, but with no luck.

I also tried https://github.com/goldfire/CanvasInput but it seems to not work either with Pixi. I can get a text input showing up using a seperate canvas, but not Pixis. 

Copying Rendered Sprite to New Texture

$
0
0

So in my previous post on these forums, I got help using some PIXI filters.  Great.  Now, I want to turn the filtered result into a new Texture object so that I can use it in a 3rd party system.  I basically just need a "screenshot" of the filtered results. Once I have the new texture, I no longer need the original Sprite (at least not for this system). The new texture doesn't need to update or anything like that.

I thought I had a potential approach, but it's not working. Just in case I'm barking up the wrong tree, first I want to confirm that I'm going about this in the most efficient manner. First we create the base Sprite and give it the filters in question.  Because I want to apply the shaders, I think I need to render the sprite to canvas first, so I try to do so on an off-screen canvas.  Last, I attempt to create a new texture using the fromCanvas method.  If that's the wrong way to go about this, let's talk about a better way instead.

If that is the right way to go about it, here's the problem: fromCanvas never captures the texture. I must be doing something wrong at some stage.  Here's the code.  Note that instead of using an off-screen canvas, I'm currently using an on-screen canvas, because I wanted to confirm that the image is rendering correctly on the second canvas.  It is.

// Create the main stage.
var width = window.innerWidth;
var height = window.innerHeight;
var renderer = new PIXI.WebGLRenderer(width, height);
document.body.appendChild(renderer.view);

var stage = new PIXI.Container();

// Create the offscreen sprite and stage.
var offscreenSprite = PIXI.Sprite.fromImage('Base3.png');

/* Code to create and apply filters here. */

var offscreenStage = new PIXI.Container();
var offscreenRenderer = new PIXI.WebGLRenderer(offscreenSprite.width, offscreenSprite.height);
offscreenStage.addChild(offscreenSprite);

// Put view onscreen for testing purposes.
document.body.appendChild(offscreenRenderer.view);

It doesn't seem to matter whether I try to capture the texture before or during the main loop.  Here's before:

offscreenRenderer.render(offscreenStage);
requestAnimationFrame(update);
var sprite = PIXI.Sprite.from(baseTexture);
sprite.x = width / 2;
sprite.y = height / 2;
sprite.anchor.set(0.5);
stage.addChild(sprite);

function update() {
    requestAnimationFrame(update);
    renderer.render(stage);
    renderer.render(offscreenStage);
}

And here's the alternate approach, capturing the texture during the main loop. This version even tries to update the texture during the main loop, even though I don't want to do that.  It doesn't help!

offscreenRenderer.render(offscreenStage);
requestAnimationFrame(update);

var sprite;
var firstPass = true;

function update() {
    requestAnimationFrame(update);
    renderer.render(stage);
    renderer.render(offscreenStage);
	
	if(firstPass ) {
		var baseTexture = PIXI.BaseTexture.fromCanvas(offscreenRenderer.view);
		sprite = PIXI.Sprite.from(baseTexture);
		sprite.x = width / 2;
		sprite.y = height / 2;
		sprite.anchor.set(0.5);
	}
	else {
		sprite.texture.update();
	}
}
update();

Using console.log, I can confirm that fromCanvas is returning the default, empty results.  There's no on-screen results, because the onscreen sprite has no texture.  Any ideas?

 


2D Camera

$
0
0

I've taken a look at pixi-viewport and I really like it except for the ease drag part and the fact that it can't return a PIXI.DisplayObject that I can add myself to the stage and render it.      t
So I have a Pixi.Container I want the camera to move around instead of it inheriting the render and using its own render loop.

Basically I want the same result as the Phaser.io Camera

 

Maybe the documentation is just confusing me, but I can't seem to get it to work like I want.

 

Is there any other way to do this? Because I want to have a GUI overlay.

How to draw an infinitely zoomable SVG file?

$
0
0

I have a detailed SVG file, and I want to be able to zoom in and out of it in-game, by a large factor, in realtime, while still maintaining perfectly crisp antialiased edges.

From what I've gathered, PIXI's SVG support is limited to pre-rendering a raster texture on load, which wouldn't work here as the required resolution for the closest zoom level would create an unmanagably huge texture.

I don't need support for gradients etc, just simple colours and paths.

I could triangulate the SVG file using something like svg-mesh-3d and then render it out as a mesh, however that leaves the question of how to render out the colours properly - I'm not quite sure how a PIXI mesh object could be made to handle this. Perhaps some kind of shader? Also, the triangulation has the downside that smooth curves will have a limited 'resolution' depending on the number of triangles, but that's not a massive issue for my application.

Is there a better way I'm missing? If not, any guidance on how to handle the colour rendering on the mesh would be appreciated.

Pixi Spine runtime error

$
0
0

I'm trying to use some spine animations in a large Pixi application at work. It's mostly working but I'm getting intermittent runtime errors coming from the Spine objects.

This error is:Uncaught TypeError: Cannot read property 'transform' of null
    at Spine.e.updateTransform (pixi.min.js:formatted:4401)
    at Spine.autoUpdateTransform (Spine.ts:479)
    at e.updateTransform (pixi.min.js:formatted:4405)
    at e.updateTransform (pixi.min.js:formatted:4405)
    at GameScene.e.updateTransform (pixi.min.js:formatted:4405)
    at e.render (pixi.min.js:formatted:8605)
    at Function.ScenesManager.loop (ScenesManager.ts:273)
    at t.emit (pixi.min.js:formatted:13126)
    at t.update (pixi.min.js:formatted:13068)
    at _tick (pixi.min.js:formatted:12988)

The error is coming from PIXI.Container, line 323 because this.parent is null. This is a bit bonkers because this is only being called because the spine object is in the children list of the scene being rendered.

this.transform.updateTransform(this.parent.transform);

I dug in a tried to isolate the problem and found that somewhere in the Spine update function the parent was being set to null. In Chrome debugger I put in some conditional breakpoints for

dt>0 && this.parent==null

and found that the culprit was line 184

this.state.apply(this.skeleton);

Before this line the breakpoint doesn't trigger, after it it does, with this.parent being null.

I had a read through AnimationState.apply and I can't for the life of me see anything that would be setting the Spine parent state. So my question is can anybody else see anything in there that might be creating this effect?

I should say that the application does a bunch of complicated pooling of symbols, so the Spine object might be getting removed and sent back to the pool then re-added frequently. But my understanding was that since JS is mostly single threaded if this.parent exists on line183 but not 185 something between there must be setting it to null.

I'm not extending or doing anything else to the Spine object. Unfortunately I can't give out any coded to show the context. I'd be really grateful if anybody has any suggestions or input.

PIXI es6 & Babel

$
0
0

Hi all

After a few working  projects in PIXI on es5,  we're now starting to try and build a framework using es6 & babel.  We have a boilerplate setup and have got the basics working, though it is slow.  Because PIXI.js modules aren't decoupled, it takes a good 5 seconds+ on a simple project to recompile on each save & refresh the browser.  I understand there is work possibly planned for V5 on this, but are there any workarounds in the meantime anyone has found to make the workflow a little quicker?

Thanks in advance!

Add raw WebGL texture to Pixi.js

$
0
0

Hi,

I want to create a PIXI.Texture from a WebGL texture. Unfortunately, I have not managed this yet. My WebGL texture is created in the same WebGL renderer context as Pixi with "app.renderer.gl.createTexture()", this works. Then I tried to hang the texture on an existing PIXI.Texture:

sprite.texture.baseTexture._glTextures[app.renderer.CONTEXT_UID].texture = myWebglTexture

Even without the above line of code, my WebGL texture is inserted into the canvas element and always swaps the texture of the last sprite loaded in Pixi (Change-Texture.mp4).

Unfortunately I cannot swap my WebGL Texture with a texture of a specific sprite :-(

 This approach has unfortunately not worked:

Does anyone have an idea?


Thank you for your support!

Viewing all 3978 articles
Browse latest View live


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