ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
363 stars 75 forks source link

Question: viewport y #32

Open err0 opened 12 years ago

err0 commented 12 years ago

I can't seem to get a viewport to render only on the bottom part of the canvas. I can get it to render on only the top part just fine. canvas size is 500,320

// render top half - works
viewport_top = new jaws.Viewport({max_x: width*32, max_y: height*32, height:160 })
//expected this to render to the  bottom half of the canvas
viewport_bottom = new jaws.Viewport({max_x: width*32, max_y: height*32, height:160, y: 160 }) 
err0 commented 12 years ago

the problem I am trying to solve with this is that I have a tilemap of tree sprites. the player is centered on the full "ground" tilemap and I want to draw the sprites with y < player first, then the player, then the y > player sprites.

I think I'll try using TileMap.atRect next and simplify my viewports.

ippa commented 12 years ago

Pretty busy this weekend but i think we need to talk about this on irc ..not totally sure what you mean.. Im "ippa" on freenode

err0 commented 12 years ago

Here is what I ended up doing. It's working pretty well.

viewport.drawTileMap( tile_map_b )  //collision layer
viewport.drawTileMap( tile_map) // grass & ground
viewport_t.draw( tree_map.atRect(jaws.Rect(player.x - 250, player.y - 160, 500, 128 ))) //trees when above player on screen
viewport_t.draw( player ) //player centered on canvas
viewport_b.draw( tree_map.atRect(jaws.Rect(player.x - 250, player.y + 32, 500, 160 ))) //trees when below player on screen

I am still curious if there is a way to offset a viewport away from top left.