Five Nights at Freddy's Camera

Well actually you don’t need a button tag at all - that was just an example. You can use any element as a button so you can just have a single img tag as well.

1 Like

Ok, I am adding the buttons now. If I have trouble than I will tell you.

Trouble already. It says ‘null’ is not an object. No idea why.

Just a word of advice. If you just post error messages with no context, it is impossible for anybody to help you. Always be thorough when providing others the information they need to diagnose a problem you might be having. Posting a link to your scene is normally the best way to do this. Accompany that with any instructions required to reproduce the error. If you don’t, there can be a lengthy exchange where the people trying to help you try to get the information they need to figure out what’s going on.

1 Like

I don’t know how to explain. Launch the game here.

I have a screenshot here. Plz help me to figure out what is wrong and how to fix it.

It says rotate1 is null, so not an object. As you are getting rotate1 with following code:

var rotate1 = document.getElementById(‘rotate1’);

it essentially means javascript can not find a dom element with id ‘rotate1’. So, there is no tag in your html which has an id of rotate1.

Also, unrelated, calling getElementById on every update is horribly inefficient, do it once on your initalize like this:

pc.script.create('Camera', function (app) {
        // Creates a new Camera instance
        var Camera = function (entity) {
            this.entity = entity;
        };
    var a = 0;
        Camera.prototype = {
            // Called once after all resources are loaded and before the first update
            initialize: function () {                    
                var rotate1 = document.getElementById('rotate1');

                if (rotate1 != null) {
                    rotate1.addEventListener('click', function() {
                        this.entity.rotate(0, a - 1, 0);
                    });
                }
            },
    
            // Called every frame, dt is time in seconds since last update
            update: function (dt) {

                
            }
        };
    
        return Camera;
    });

Take a look at: http://answers.playcanvas.com/questions/15/how-can-i-add-a-hud-to-my-playcanvas-game

I have an ID of “rotate1”


I also switched the script to initialize. Still says that, except only once this time.

Just putting html where there is supposed to be javascript will not work. Have a look at the link I provided above, read it, make sure you understand it. Then try again.

I don’t want to discourage you, but could it be that you don’t have much experience programming with js/html or programming in general? Might I suggest you first try basic javascript/html coding before trying to make a game. It seems you are now just copying pieces of code without grasping their meaning or understanding the context. This will lead to a lot frustration, both from you and the people trying to help you. Before copying something, make sure you understand what you are copying.

I know this post might sound harsh, but game development can be challenging, even if you make something simple as ‘a 5 nights at freddy’s game’. Don’t try to run before you can walk.

1 Like

I will not deny that I am almost a total noob, but I need to get this game out by next month. I have no time for relearning everything. I used that question in the past and it doesn’t help with what I’m doing here.

The answer to that question and specifically the part “Use Standard DOM Elements” is exactly what you need.

You have an error in your camera js
var rotate1 = document.getElementById(‘rotate1’);
rotate1 isn’t an element and so in the following line you have an error