Jump to content

Up and down key press scrolling page


Recommended Posts

Hi All.  I've just created a Phaser3 game and added it to an asp.net page.  When I use the up or down keys the page scrolls rather than the character moving.

I understand that this is something to do with event.preventDefault() for keydown, but I can't get it working.

It works fine in a basic html page, but not in the asp.net page.

Here is the html page that DOES work:

<!DOCTYPE html>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="phaser.min.js" type="text/JavaScript"></script>
    <script src="game.js?1" type="text/JavaScript"></script>
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />

<body style="text-align:center; padding-top:250px; padding-bottom: 3000px;">

    <div id="otterGame"></div>


Working live example: http://otter.org/GAMETEMP_30_5_2019/index.html

Here is the asp.net page that is having the problem:

<%@ Page Title="" Language="VB" MasterPageFile="~/Public/Main.master" AutoEventWireup="false" CodeFile="MediaAndResources_Game.aspx.vb" Inherits="Public_MediaAndResources_Game" %>
<%@ Register src="../controls/V2/BreadCrumb.ascx" tagname="BreadCrumb" tagprefix="uc1" %>

<%@ Register src="../controls/V2/QuickLinks_7.ascx" tagname="QuickLinks_7" tagprefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link rel="stylesheet" type="text/css" href="../Game/style.css">
    <script src="../assets/js/phaser.min.js" type="text/JavaScript"></script>
    <script src="../Game/game.js?2" type="text/JavaScript"></script>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder_imageBar" Runat="Server">
    <uc1:BreadCrumb ID="BreadCrumb1" runat="server" PageTitle="Game" Level1_Title="Home" Level1_URL="Default.aspx" Level2_Title='' Level2_URL="" Level3_Title="Game" />

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder_Body" Runat="Server">
    <div class="row margin-bottom-20">

        <div class="col-md-3 col-sm-3">
            <uc2:QuickLinks_7 ID="QuickLinks_21" runat="server" />

        <div class="col-md-9 col-sm-9">            
            <h1>Otter Madness</h1>
            <div id="otterGame"></div>


You can see the live page here: http://otter.org/Public/MediaAndResources_Game.aspx

I'm adding the keys like this:

this.upKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
this.downKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);

...and then checking their state in the update function like this:

if (this.upKey.isDown) {     
    //Do some stuff
}else if(this.downKey.isDown){
    //Do some more stuff        

Any idea what's I can do to fix this please?

Thanks very much!


Link to comment
Share on other sites


  • Recently Browsing   0 members

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