Hello, I have this piece of code in update method of my scene:
if(this.shake==undefined){
this.shake = new Phaser.Cameras.Scene2D.Effects.Shake(this.cameras.main);
this.shake.start(1000);
}
But nothing happens. Why? I wrote that, because I read that in docs. I know, that there is another way to shake main camera (calling directly method shake() on main camera). But I am wondering, why that first way don’t work…
Thanks!
Phaser.Cameras.Scene2D.Effects.Shake (along with the other classes from the Effects namespace) is an internal class that you shouldn’t instantiate yourself. It is not standalone because the camera itself has to be aware of it and maintain it. (camera).shake() operates on the camera’s own instance of the effect, which is the only instance that will actually be updated and rendered.
If for some reason you want to work with an Effects.Shake object directly, you can access the camera’s internal object through (camera).shakeEffect. However, I don’t think it would be particularly useful because all properties of the effect can be configured through the shake() method.
I understand. But then - what is best way to study docs? Or it is not good idea?
Is that inability of creating for example Shake effect from Phaser.Cameras.Scene2D.Effects.Shake only “problem” of Effect namespace and other classes from docs would work, or it is really not good idea to study from docs, because lot of classes won’t work this way?
I am new to Phaser and I want to “master” it, so where to start? Is it possible to learn Phaser from docs? Because when I see class with lot of method it is better for me for entire “picture” of what can I do…(Instead of learning only part of it from tutorials).
The docs contain everything, even private and internal functionality. I recommend studying from the examples and consulting the docs when necessary. You can also use Rex’s notes, which are a little less formal and perhaps easier to understand. If you already know JavaScript, reading Phaser’s source code is also a good alternative.