grapefruitjs / grapefruit

Outdated, I recommend you use photonstorm/phaser instead!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started

krazyjakee opened this issue · comments

Hi there guys,
I have an issue with the basics of gf.

Here is my code so far:

$(window).ready ->

  game = new gf.Game 'game',
    width: window.innerWidth
    height: window.innerHeight
    background: 0x000000
    interactive: true

  game.loader.on 'complete', () ->
    game.loadWorld 'island2'
    game.render()

  game.loader.on 'progress', (e) ->
    false

  game.loader.load [
    name: 'island2'
    src: 'resources/map/island2.json'
  ]

When I run it, I get:

Uncaught World "island2" needs to be preloaded before being added to a game! 

I think what's needed here is for a simple "getting started" guide on how to start from scratch as the api doesn't match the code in your examples. IE using

game.loader.load(things)

instead of

gf.Loader(things)

Thanks and great work!!!!

I think you meant to do

game.loader.load [{
    name: 'island2'
    src: 'resources/map/island2.json'
}]

load takes an array of urls or an array of objects with name/src properties.

I agree we need guides, but I want to get the code stable first. Also, you can do both ways, game.loader is just an instance of gf.AssetLoader already created for you.

I did a basic tutorial here grapefruit basics which is an extract of one of the examples in the maptest project. I'm learning too.

@englercj it's coffeescript and it's passing the variables through so it must be working. I'll double check later.

@mgutz nice tutorial. Maybe I need to use gamestates to make it work?

The api says that when game.loader.load is passed a map, it loads all the assets. Is it possible the game loader complete event is being fired before loading the map assets?

I don't know much about coffeescript, maybe let me see the compiled javascript (or a page that isn't working) and I can help you out?

The Game object creates a default GameState for you, and uses that unless you tell it otherwise.

Updated the tutorial to use array of objects

I'd appreciate that, thank you 🍔

I'll push it up later and start my own very simple "Getting Started" tutorial.

It probably isn't a complete enough overview of the problem but In the mean time you can paste my snipped into: http://js2coffee.org/

OK I see, this is because the world loader expects the tileset image location (in the TiledEditor json) to be relative to where the json file is.

So you load the json file from resources/maps/island2.json and the tileset image location is set to resources/img/free_tileset_version_10.png, then that means the loader will try to load from resources/maps/resources/img/free_tileset_version_10.png which 404s and since you are not listening for errors you don't know it happened.

Change you tiled json (on line 67) to use ../img/free_tileset_version_10.png instead and it should work fine.

That's great thank you very much!

I also needed to run the index.html on a port and not just through the file system.

http://localhost:5656/jQuest/

not

file:///C:/Users/Jake/Documents/GitHub/jQuest/index.html

Thanks again!

That is also true, unless you run Chrome/FF with special arguments to allow ajax on the file:// protocol.