Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:23:09+00:00 2026-06-17T16:23:09+00:00

im creating a simple game and, I need some direction for debuging some data.

  • 0

im creating a simple game and, I need some direction for debuging some data.
i have a div in my HTML file, that I want him to show some data that change when some variables get change by the user actions.

for exmple i got var xPosition, I want to send the data to a div in the HTML, so i can see the current state of xPosition.

i realy dont have any idea where to start creating this functionlity.

my questions:

  1. is it possible to create event inside this class and register some
    element to him that will show all the changing data?
  2. do i have to use a some a timer for that sort of thing?

this is the “class”:

(function ($) {
    $.Player = function (element) {
        this.element = (element instanceof $) ? element : $(element);
        this.movmentSpeed = 10;
        this.size = $(element).width();
        this.xPos = 0;
        this.yPos = 0;
    };


    $.Player.prototype = {
        //register events
        InitEvents: function () {
            var that = this;
            $(document).keydown(function (e) {
                var key = e.which;
                if (key == 39) {
                    that.moveRight(400);
                } else if (key == 37) {
                    that.moveLeft();
                }
            });

            this.element.css({
                left: this.xPos
            });
        },

        //movment functions
        moveRight: function (worldWidth) {
            if ((this.xPos + this.size) <= worldWidth) {
                this.xPos += this.movmentSpeed;
                this.element.css("left", '+=' + this.movmentSpeed);
            }
        },
        moveLeft: function () {
            if (this.xPos > 0) {
                this.xPos -= this.movmentSpeed;
                this.element.css("left", '-=' + this.movmentSpeed);
            }
        }
    };

} (jQuery));

here the HTML:

<div id="player">
<div id="debugData"> <div>
<script>
var player = new $.Player($("#player"));
        player.InitEvents();

</script>

(sorry for my english)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:23:10+00:00Added an answer on June 17, 2026 at 4:23 pm

    jsFiddle Demo

    I’d say having an internal function inside the Class would help. Maybe even having a setting where you turn the logging on by doing player.logging = true;, and having it default to false;

    In your prototype just add a public prototype variable for logging = false, and our prototype function log().

    The internal function you could use could be something as simple as:

        logging : false, // our default
    
        log : function (str) {
            if (this.logging) {
                $('#debugData').html(str);
            }
        },
    

    This way you could leave your log(this.xPos); (or whatever you want to log) within your code, and by removing the player.logging = true; when you instantiate your class, they won’t show up, till you put that code back in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im creating a simple bowling game using OOP, and i want to have a
I am new to XNA, and I am creating a simple game. Sorry that
Hi guys I am creating a simple game using cocos2d-x and blackberry. I need
I'm creating a simple 2D game in javascript/canvas. I need to figure out the
I'm creating a simple web game that uses web sockets for to stream updates
I'm creating a simple board game in Java using Swing with an AI that
I need some help creating a very simple forum in a existing model. What
I'm creating a simple game using GDI+ in C#. First of all I need
I'm creating a simple black jack game using the Easy 68K simulator and need
I am creating a somewhat simple game, and I need to keep track of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.