Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


JavaScript based 2D / 2.5D game engine


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 martens.ms   Members   -  Reputation: 100

Like
0Likes
Like

Posted 25 January 2011 - 08:31 AM

Hello everybody!

I just found this forum and thought that it would perfectly match my current development stuff.

So, I'm currently developing a little JavaScript-based and lightweight engine for browser gaming. The target are mobiles or slower devices.
I'm currently challenging the architecture. It is built upon mainly in these different "objects / constructors"...

Current architecture:
- Cache: The cache is accessible by everyone, it manages stacks and their entries (via id). e.g. models, levels, objects are hosted there.

- Engine: The logical level, engine loads levels, manages the objects and calls the compositor
- Engine.Hitmap: The hitmap with simple true/false entries.

- Compositor: Translates Objects (Tilegrid Coords & Sizes) to Pixel-based ones (if 2D) or to the 2.5D or 3D coordinates. Can be switched anytime (maybe compositing scheme?).

- Renderer: Uses different technologies to render. Same structure required for all renderers. Currently an HTML-generating renderer, but maybe Canvas or WebGL later.

Examples / Links:
You can find a sample game (wherein I'm experimenting a lot, so please don't flame if it's not working) at
http://ninja.martens.ms/game.html

I also built a little editor (rapidly in about 30min) which is in my opinion "just a frontend for the engine and manages it":
http://ninja.martens.ms/editor.html

To help you have a clue what's going on in these Classes, I created a JSDoc reference:
http://ninja.martens.ms/docs


My current challenge:
The Quest and Player- or NPC-logic. I currently implemented a simple Engine.Character Class that creates a character instance per object. I now have the problem for using quests or other "global interface interactions" that may influence the characters or NPCs.

Imagine you have an NPC walking around until you talk to him. Then he wants you to follow to a given position. After you followed, he wants to show you how the game works (e.g. fighting and stuff). You get points, upgrades and stuff - or quests you will have to solve. These quests are in my opinion something like attached events for objects. E.g. "destroy object with id bla" will be triggered if the object was destroyed. The callback function attached on it will now be called and upgrades the questmap.
...well, or something like that.

I currently have no idea how to realize that (in a well-designed game architecture). So I'm asking you for suggestions or ideas.
You are the pros, I'm just the JavaScript ninja that has no clue of game engines =D

Please have in mind that the underlying DOM (Document Object Model) in web browsers is heavily slow - compared to other environments.
That's why I built the structure in that way.

...I want to thank for any idea or opinion on that!

Greetings,
Christoph
Currently developing a 3D / 2.5D tile-based browser engine, based on polygons, rotating bounding volumes etc.

Link: http://github.com/martensms/lycheeJS

Sponsor:

#2 fatkat   Members   -  Reputation: 100

Like
0Likes
Like

Posted 27 January 2011 - 04:31 PM

Dude,

AWESOME I'm doing javascript game development myself!

Your editor is the coolest thing you've got. That's awesome. Are you just relying on animated gifs to do animation? I am thinking of doing image sets for animation so I can control which animation is playing depending on user interaction. Perhaps a set of animated gifs for different animations and swapping the images? Not sure the best way to do baked animation.

So far I am staying out of the <canvas> although my 1st ever completed game (a tetris clone) uses <canvas> check that out here: http://cedarrapidscl...js/tetrominoes/

My intention is to create a new game prototype each week.. The first prototype is a work in progress that will be completed this Saturday. I'm trying to learn collision detection and basic physics - see it here: http://cedarrapidscl.../tyler/messing/

I like your overhead tile based game it's got a very rpg like feel to it and reminds me of the original Zelda.

As far as game engine design and architecture, at this point why worry about it? Make the thing work and if it's an ugly mess, you can clean it up on your next version. When I first started trying to make my physics engine, I was trying to take everything into consideration and create an object hierarchy for linking and such and I just decided and getting nothing visible done, I figured TO HELL WITH IT and just to make SOMETHING work - at least that way I know right away if my game idea has any potential and is worth porting and developing into a full game.

After I get an idea that's amazing and will make me quite rich, I'll spend the time perfecting the engine (and converting it to a platform where I can charge - an app store)

#3 Sirisian   Crossbones+   -  Reputation: 1770

Like
0Likes
Like

Posted 28 January 2011 - 01:09 AM

I would have converted it to <canvas> before posting this. Using the DOM like you're doing isn't advised and flickers in Firefox 4b9. I mean it wasn't recommended when people tried to make games in it when it came out. Good start though. Try not to use copyrighted images. There are free sprite libraries online. (Many people have very strong feelings toward copyrighted content).

#4 martens.ms   Members   -  Reputation: 100

Like
0Likes
Like

Posted 28 January 2011 - 09:45 AM

Wow!

Your engine is good as well. Really cool.
What I would like to recommend you: Try keep the DOM window namespace clean and use classes and constructors instead of functions. Use prototype to declare functions that depend on the objects varied properties. That allows to save bunches and bunches of memory, because it then will only be linked to the stack instead of copied everytime you use it.

Nope, I'm using spritemaps and background positioning. I will maybe use translate3d() instead of background positioning - but this is still laggy and buggy on most Webkits.
Spritemaps are the fastest way (remember: DOM Node interaction is always slow!) and allows auto-generated keyframe animations using CSS3 - that's kinda cool, no one else got it yet =D

My renderer also uses feature detection. If the browser supports css animations, then it will generate keyframes. If not, then the renderer update cycle is curryfied by the animation plugin and walks through the temporary animatedObjects-cache.


Related to the editor:
I was just too lazy to create the JSON arrays - well, I was too stupid and made bunches of typos...so I decided to hack a level editor (within about 20mins) - it's unusable but it does it's job =D

Well, I prefer using the DOM because Canvas is still the slowest thing they ever invented. Considering huge 2.5D worlds - rendering with canvas is impossible.

I read a lot the last days about a component based structure. That flattens your hierarchy and let's you implement different components that may effect a single object (if it requests it) or bunches of objects (e.g. when the compositor applys them). A really cool technique.

A really cool article is the one on cowboy programming - it's 2007, but hey - they got more limited cpus than nowadays =)
http://cowboyprogram...-your-heirachy/


The workspace-divided architecture wouldn't make sense for browser development...long render pathes before something happens and too much heap attached to the objects.
A cool guide for it was: http://dundee.cs.que...AV_Architecture


I'm concentrating on RPG with my RPG engine (as you may have found out), but it's not complicated to add more dimensions to it - that's why compositor and renderer are strictly seperated.

I implemented the first component for the player controls to show how I think it would make sense. I have no controlling scheme, so every component requests just what he wants from the engine controller.
http://ninja.martens.ms/beta/game.html


Just click on the map (viewport) to test the pathfinding algorithm. Sometimes it doesn't work...needs some improvements, but it walks mainly like AStar, but more dependend on velocities and directions.


...and I got stuck a lot with the AStar Pathfinding stuff - meanwhile I got a bit bored and coded a JavaScript Class that parses JavaScript Documentations =D
http://ninja.martens.ms/beta/docs.html
(I really like it - kinda kool =D)

How my engine looks like:


Posted Image


(oh dude, user experience on Mac OSX sucks hard for newbies. I prefer my Linux/Gnome =/ I know, it's a flow chart. And it's not a flow. Sure.)

What the parts do:

Engine
The Engine decides still all logic levels. It applies Physics and bunches of stuff - and manages the contens or media.

Cache
The Cache is accessible anywhere, he caches dude. Has a stack managing hierarchy and allows getting complete stacks (e.g. cache.get('models')) or targeted entries (like cache.get('models','flower-red'))
Controller
The Controller has bunches of capabilities. It manages the Modules (loaded as Plugin-like system). Modules request everything they want. That could be a binding on an object's event (e.g. "bind me on object x when it's bumped, because I have sweet graphics, dude") - or on something like a DOM Element. The Player Module is binded on a DOM Element, because it listens to a DOM (host environment) event, the keyCode. Each module is able to listen on multiple events (and attach different handlers on them). (here's a todo: implementing different handling functions, but scheme is done)

Compositor
The Compositor manages the objects position and dimensions. He's the guy that knows the relations between our world grid and the pixel-related sizes (the 2D compositor). A 2.5D compositor for example would be able to handle depth sorting and zIndexes as well. He decides, which composites (objects) are dirty and routes them to the Renderer.

Renderer
The Renderer is really dump and smart at the same time. He's the guy that manages the viewport, the object rendering and the relations between them. Have a look at the player module - it shifts the viewport if you navigate to the border of the viewport (via keyboard WASD)

Example: An Object has more information than a Model. It is positioned. A Model offers only information about the object's dimensions, media and animations (and spritemap positions)
Object (position) -> attached Model (dimensions, animations, media)


So, that's it for now.
Greets
Currently developing a 3D / 2.5D tile-based browser engine, based on polygons, rotating bounding volumes etc.

Link: http://github.com/martensms/lycheeJS




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS