android - My Scrolling Bitmap Canvas is too slow to use -
i learning program android. i've made couple of basic games, learning i'd make car driving game. simplest way thought of doing keep car in middle of screen , scroll background give illusion of movement.
as experiment figure out engine, created 2048x1200 bitmap load png. map. create new bitmap of 1024x600 cropped map display on screen. getwidth() & getheight() give these dimensions. take different crop each time based on movement show on screen.
unfortunately find slow use. car have move @ snails pace if wanted smooth. 18fps.
i using james daniello's simple game loop
i read following stack overflow article says keep object creation out of main loop as possible, doing best can.
how draw lots of bitmaps on screen in android game without slow performance
also of use article romain guy on keeping bitmap same format screen stop having transformed displayed on screen, costly.
bitmap quality, banding , dithering
i'd figure out best can achieve canvas , bitmaps before move on opengl. @ limitations, or should differently? find 18fps when scrolling map 1px @ time smooth scrolling.
private bitmap track; private bitmap visible; private point position; private int fps = 0; private long lastfpstime = 0; private int fpscount = 0; paint ptext; public void draw(canvas c){ visible = bitmap.createbitmap(track, position.x + 512, position.y + 300, 512, 300); position.x++; c.drawbitmap(visible, 0,0, null); c.drawtext("fps: " + fps, 10, 10, ptext); } public void init(resources resources) { // load map track1.png track = bitmap.createbitmap(2048, 1200, bitmap.config.rgb_565); bitmap track1 = bitmapfactory.decoderesource(resources, r.drawable.track1); track = track1.copy(bitmap.config.rgb_565, true); position = new point(0,0); //setup text paint object ptext = new paint(); ptext.setcolor(color.white); ptext.setstyle(style.fill_and_stroke); } public void update() { fpscount++; if (system.currenttimemillis() - lastfpstime >= 1000){ lastfpstime = system.currenttimemillis(); fps = fpscount; fpscount = 0; } }
you creating new bitmap on every frame draw. it's extremely expensive. should use version of drawbitmap() takes source , destination rectangle instead.
Comments
Post a Comment