Featured post
Design decisions / advice for a simple game on Android -
i need advice on best way implement scrollable playing field in simple game. field consists of multiple rows, 9 cells in each row. rows can dynamically added , removed during course of game. each cell has digit in it, , optionally several overlayed images, selection, selector over, crossed out, etc. (see pic below). user should able click on individual cells of row select/deselect/cross touched cells. @ point in game there can 0 3000 cells (0 333 rows). field should scroll , down smoothly.
i thinking having listview each row being row on field. way add/remove rows dynamically during game. however, how should implement row: have 1 bitmap representing row, , when user touches -- coordinates of touch area, , find out cell affected, , act upon that. possible touch coordinates of row in listview? if not, should place 9 dummy image placeholders in each row, , act on user touching those? performance?
or should have 1 huge bitmap / canvas representing entire field, place inside scrollview , calculate coordinates , update user interacts it? going faster or slower listview?
any other solutions?
i prefer "regular" app type game, not loop-based game, don't think need redraw 30 times second.
i pretty new android. thank suggestions.
you can make kind of setup run "game loop" / surfaceview combination. means no listview, custom drawing , event handling. luckily event handling isn't difficult, , you'll win later on because you'll have greater control on interface if had gone bunch of customized views , layouts.
i'd avoid www.droidnova.com tutorial, uses hashmaps unnecessarily, cost in performance.
here's how i'd go it:
- create object hold cell data. example, i'd use object id (to print), , x , y draw on screen.
- decide on board size fit on screen without scrolling, 10x10. you'll add scrolling later.
- create 2-dimensional array of cell objects lengths boardsize x boardsize. fill objects id , x , y position on screen.
- in custom ondraw, iterate through each "row" , "column" of single array , draw object @ stored x , y value.
so you've got grid of objects displaying on screen. want restrict number of rows displayed , add functionality change rows visible. done follows:
- during initialization, set global ints mcurrentrow = 0 , mnumvisiblerows = 3. these define "view window".
- modify drawing code draw rows starting @ mcurrentrow , ending @ mcurrentrow + mnumvisiblerows. result of should ever see mnumvisiblerows rows, , group of rows see depends on set mcurrentrow to.
- add triangles right of grid drawing , have tap touch events in areas map increments/decrements of mcurrentrow. obviously, should not allow value go outside row count bounds.
- if want classy, draw line between triangles scroll area, , map touch events there
newcurrentrow = (touch.y / canvas.height()) * boardsize;
needs tweaking, idea.
this approach has downside of showing full set of rows @ time, scrolling wouldn't smooth. however, have complete control on canvas , draw, little more math implement smooth scrolling mechanism offset fractional row height in y-direction instead of whole rows.
- Get link
- X
- Other Apps
Comments
Post a Comment