Tag: development
How to: Create a scrollable Map with Cells
by Martin on Jan.04, 2010, under how to, tutorial
This how to will show you how you can create a simple 2D Map with Cells to place stuff on it. Just like the old school SimCity.
The first thing you need is an Activity with a SurfaceView and a Thread to trigger the drawing. Who doesn’t know these fundamentals, please read my series on 2d graphics first.
Lets start with the smallest unit for our map: the Cell.
Each Cell will have a background color and a unique ID.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package com.droidnova.android.games; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; /** * A part of the map. */ public class Cell { public int _id = 0; public int _backgroundColor = Color.GREEN; /** * Konstruktor. * @param id */ public Cell(int id) { _id = id; } /** * Draw the cell * * @param canvas Canvas to draw on. * @param paint Color of the "pencil". * @param x X coordinate. * @param y Y coordinate. */ public void draw(Canvas canvas, Paint paint, int x, int y) { paint.setColor(_backgroundColor); canvas.drawRect(x, y, x + CellMap._cellSize, y + CellMap._cellSize, paint); paint.setColor(Color.BLACK); canvas.drawText("" + _id, x + 1, y + 10, paint); } } |
On line 32 you see, how we draw the cell. The variable _cellSize is a static variable from CellMap, which will be introduced later. Everything else should be already known.
(continue reading…)
Ubuntu 9.10 with Eclipse and ADT – Problems
by Martin on Oct.26, 2009, under how to
Sometimes I am a bit over motivated. Thats the reason I upgraded my Ubuntu to 9.10 RC1 yesterday.
Nearly everything worked fine and after 90 minutes downloading and installing Ubuntu 9.10 booted the first time.
The disillusion followed today: What happened with my Eclipse installation?
The LogCat view has no logging type buttons, the Devices view has lost its button for stopping processes and some windows don’t accept a mouse click on their buttons (mostly the OK button). I have to press Enter to get them work.
After a short search I found this bug report for ubuntu: https://bugs.launchpad.net/ubuntu/+source/gtk+2.0/+bug/442078
A workaround is also mentioned there:
Create a launch script for eclipse with the following code:
#!/bin/sh GDK_NATIVE_WINDOWS=1 /path/to/eclipse
I am not sure if Ubuntu is responsible or Eclipse, but after using this launch script, everything worked fine.