See the Android Canvas class:
http://developer.android.com/reference/android/graphics/Canvas.html

And redrawing at approx 7 frames a second (150ms) there should be no 
problem.  To refresh at 30fps or faster a suggest you adapt your your code 
to use OpenGL ES 2.0.

On Sunday, December 1, 2013 4:18:18 PM UTC, toki wrote:
>
> Hello,
>
> i am developing a game where something happens with some objects in one 
> thread and the situation is painted every 150 ms. Currenty I experimented 
> with painting on a java.awt.Canvas, which works fine.
>
> But now I would like to paint in android instead. I am looking for some 
> tips how to start this.
>
> In android I have seen an example where you can paint on a 
> android.view.View. However, I don't know, if it would perform well, if I 
> paint there like I did on the java.awt.Cavas.
>
> I attach my painting on the java.awt.Canvas for better understanding.
>
> br
> Tobias
>
> [code]
> public void paint(Graphics g) {
>         
>         if (offscreen == null) {
>             offscreenImage = this
>                     .createImage(getSize().width, getSize().height);
>             offscreen = offscreenImage.getGraphics();
>         }
>         
>         
>
>         // Felder
>         offscreen.setColor(colBG);
>         for (int x = 0; x < this.spielfeld.WIDTH; x++) {
>             for (int y = 0; y < this.spielfeld.HEIGHT; y++)
>                 
>                 offscreen.fillRect(x * fieldSize, y * fieldSize, fieldSize,
>                         fieldSize);
>         }
>         
>         // Hindernisse
>         for (Iterator<Objekt> oiter = spielfeld.getObjekte().iterator(); 
> oiter.hasNext();) {
>             Objekt o = oiter.next();
>             for (Iterator<Position> iter =  o.getPositions().iterator(); 
> iter.hasNext();) {
>                 Position p = iter.next();
>                 offscreen.setColor(Color.blue);
>                 int big = (int)(fieldSize*1.7);
>                 if (o instanceof See)
>                     offscreen.fillOval(p.x * fieldSize, p.y * fieldSize, 
> big, big);
>                 else
>                     offscreen.drawRect(p.x * fieldSize, p.y * fieldSize, 
> fieldSize, fieldSize);
>             }
>         }
>         
>         // Strassen
>         offscreen.setColor(Color.yellow);
>         for (Iterator<Strasse> iter = spielfeld.getStrassen().iterator(); 
> iter.hasNext();) {
>             Strasse s = iter.next();
>             for (Iterator<Position> piter = s.getPositionen().iterator(); 
> piter.hasNext();) {
>                 Position p = piter.next();
>                 offscreen.drawOval(p.x * fieldSize + 
> fieldSize/2,p.y*fieldSize + fieldSize/2,fieldSize/2,fieldSize/2);
>             }
>         }
>         
>         
>         // Ameisen
>         for (Iterator<Ameise> iter = spielfeld.getAmeisen().iterator(); 
> iter.hasNext();) {
>             Ameise a = iter.next();
>             Position p = a.getPosition();
>             offscreen.setColor(Color.red);
>             
>             offscreen.drawImage(ameise[a.getRichtung()],p.x * 
> fieldSize,p.y*fieldSize,fieldSize, fieldSize,this);             
>             //offscreen.drawRect(p.x * fieldSize, p.y * fieldSize, 
> fieldSize, fieldSize);
>         }
>         
>         
>             
>         
>
>         // Nest
>        for (Iterator<Position> iPos = 
> spielfeld.getNest().getPositions().iterator(); iPos.hasNext();) {
>            Position p = iPos.next();
>            offscreen.setColor(Color.green);
>            offscreen.drawRect(p.x * fieldSize, p.y * fieldSize, fieldSize, 
> fieldSize);
>        }
>        
>        // Honig
>        for (Iterator<Honigpot> iter = spielfeld.getHonig().iterator(); 
> iter.hasNext();) {
>            Honigpot h = iter.next();
>            char symbol = h.getSymbol();
>            for (Iterator<Position> iPos = h.getPositions().iterator(); 
> iPos.hasNext();) {
>                Position p = iPos.next();
>                offscreen.setColor(Color.yellow);
>                //offscreen.drawRect(p.x * fieldSize, p.y * fieldSize, 
> fieldSize, fieldSize);
>                int kap = h.getKapazitaet();
>                int bild = 0;
>                if (kap > 80)
>                    bild = 0;
>                else if (kap > 60)
>                    bild = 1;
>                else if (kap > 30)
>                    bild = 2;
>                else 
>                    bild = 3;
>                
>                if (kap > 0)
>                    offscreen.drawImage(honig[bild],p.x * 
> fieldSize,p.y*fieldSize,fieldSize, fieldSize,this);
>            }
>        }
>
>         g.drawImage(offscreenImage, 0, 0, this);
>     }
> [/code]
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to