Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 Jan 2009
Offline Last Active Nov 03 2012 08:43 AM

Topics I've Started

Javascript & HTML5: Loading of external scripts with javascript

03 November 2012 - 08:44 AM


I am making a game in HTML5 & Javascript and I'm having some issues in loading up external scripts.
The way the game is built is the data of all the game levels is stored in seperate javascript files where
a level object is created and level information is specified.

So inside my game engine I want to load 'on the fly' one level file and use that data to start a level.

I have tried using jQuery's getScript() but I only get a "Access to restricted URI denied"- exception.
I have tried having an empty script tag then changing the src-attribute to the specified path, because I read somewhere that it will load automatically if the src-attribute is changed.

One solution is to just load every level file in the HEAD-tag but there will be alot of levels and I like to compress my code as much as possible and also would very much like to learn how to do this.

Grateful for replies

Large image splitting, onload event and javascript

21 February 2012 - 01:56 AM

Greetings good people,

I am in need of a few pointers regarding the code design of my current game project.
I decided to try out javascript for the first time now that the wonderful canvas tag has been introduced.

My problem is as follows:
I'm creating type of 2D up- and sidescrolling spaceship game and the graphics of each level is a large image (PNG-format, varying dimensions but larger than the viewport). The images can get pretty large so I wonder if using javascript or/and a canvas-tag I could split the image into smaller images and storing them in a two-dimensional array. Or if another solution is more optimal e.g just clipping the large image to fit the viewport.
Even if clipping the image is a better solution, the "large image into array of small images"-solution would be prominent to the loading of my collision data. I have two seperate images with the same dimensions to each level, one with the graphics and one with color-coded collision data.
At the moment my solution is a small C# program that reads the collision data image and saves it as a text-document which I in turn load with javascript as a string and read out the data. This is a bit inconvenient because I want to ease up the level-editing process.

I also have a problem I can't quite understand:
When I load the image to a level some of my math is using the dimensions of the image,
code snippet:

function loadLevel(filename)
	levelCollisionMap = new Image();
	levelCollisionMap.src = filename+"CollisionMap.BMP";  
	levelCollisionMap.onLoad = collisionMapOnLoad(filename);	  
function collisionMapOnLoad(filename)
	 levelWidth = levelCollisionMap.width;
	 levelHeight = levelCollisionMap.height;
   // .... doing other stuff

when the collisionMapOnLoad-function executes at browser-startup the width and height of levelCollisionMap is 0, but on a refresh it is loaded.

Grateful for help

C# SDL.NET Surfaceblitting

27 July 2010 - 11:07 PM

I see alot of alphablitting problems while cruising online for the solution to my problem and I can't seem to find one.

I have a, in my opinion pretty simple task to perform:

I have a png-file that contains animationframes(with alpha per pixel).
I load this png file into my system using the Surface constructor:

Surface surface = new Surface("imageMap.png");

Now I want to split this surface into the number of frames in the png-file so I can display one frame at a time.

Now when blitting the split surfaces to the screen the alphadata ha vanished and it shows nasty edges. But when blitting the original imageMap.png to the surface a smooth edge shows.

My question is how can I in SDL.NET split a surface logically into several others and not lose the per pixel alphadata?

[.net] .NET Math library acting wierd

23 June 2010 - 02:38 AM

I've encountered an error I can't explain.
See for yourselves:

using System;

class Test{
public static void Main(){
double d = Math.Atan2(1,0);


It's some sort of precision error, though I can't explain why or how to correct it, any thougts?

Winsock problem

31 January 2009 - 02:29 AM

sup, I've been trying to get a socketserver/client app working and I got it working!, but not the way I want it to. This is my problem: On the server I'm having an increasing integer, increasing at a high rate. This integer is the data I'm sending to the client, what I want is that the client only will recieve the latest available update of the integer, even if the client is receiving at a slower pace. I'm using socket( AF_INET, SOCK_STREAM, 0 ) for configuration. code & output example, excluding all dataconversions. Server:: int i = 0; while(true){ i++; send(i); cout << i << ' '; Sleep(10); } Client:: int buf; while(true){ recv(buf); cout << buf << ' '; Sleep(100); //using higher sleep to describe my problem } Output over ~x seconds: Server: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... Client: 0 1 2 3 What I want it to output is: Server: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... Client: 0 5 11 14 I want the client to be as updated as the server, or at least as close as possible. I'm having a hard time understanding this networkprogramming so could anyone give some sample code? Thanks in advance