Jump to content

Panda - index.html


Ninjadoodle
 Share

Recommended Posts

Hi guys

 

This might be a silly question, but I'm wondering whether the index.html file that loads your finished Panda game, can be styled using css.

 

Could I for example put in a <div> and load the game at 75% of the browsers width, or do I have to load the index.html through an iframe first?

 

Thank you for advance for any suggestions :)

Link to comment
Share on other sites

Sure you can.

 

Panda engine will try to search for canvas element with id of "canvas" and if it can't find it, it will create it.

You can also change the canvas id from config:

system: {    canvasId: 'myCanvas'}

So you can place your own canvas element on your html file, put it inside div, use CSS, whatever.

You might also wanna turn centering off:

system: {    center: false}
Link to comment
Share on other sites

Hi @enpu

 

Thank you for the reply!

 

Man, I have so much to learn  :blink:

 

I managed to put a game inside the canvas element and give it a border (just learning), but I can't seem to set the size of the canvas. I think the value in config overrides that. The game stretches to the full browser height, even if I set the canvas height to be smaller.

 

Is there a way I could for example set the canvas size to 300px high and the game stretches to that size?

 

I'm a little lost with this as I think I also have to change some settings in the config file.

 

Thank again in advance!

Link to comment
Share on other sites

Ah you are right, Panda is overriding some css on canvas, i think that's needs to be fixed.

But before that, here is how you can make it work:

<!DOCTYPE html><html><head>    <meta charset="utf-8">    <title>Panda.js HTML5 game engine</title>    <script type="text/javascript" src="src/game/config.js"></script>    <script type="text/javascript" src="src/engine/core.js"></script>    <script type="text/javascript" src="src/game/main.js"></script>    <style type="text/css">        #wrapper {            height: 300px;            text-align: center;        }        #canvas {            width: auto !important;            height: 100% !important;        }    </style></head><body>    <div id="wrapper">        <canvas id="canvas"></canvas>    </div></body></html>
Link to comment
Share on other sites

Hi @enpu

 

Thank again!

 

I've tried the code and with 'scaleToFit: true' in the config enabled ....

 

changing -> height: 100% !important; to a different % or px value (for the canvas div) works ... but the wrapper height value still doesn't do anything.

 

At least now I know that it's possible :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...