Wednesday, July 27, 2011

The wild one

There's a song playing on the radio
Sky high in the airwaves on the morning show
And there's a lifeline slipping as the record plays
And as I open the blinds in my mind I'm believing that you could stay

And oh if you stay I'll chase the rainblown fields away
We'll shine like the morning and sin in the sun
Oh if you stay
We'll be the wild ones, running with the dogs today

There's a song playing through another wall
All we see and believe is the D.J. and debts dissolve
And it's a shame the plane is leaving on this sunny day
Cos on you my tattoo will be bleeding and the name will stain

But oh if you stay we'll ride from disguised suburban graves
We'll go from the bungalows where the debts still grow every day

And oh if you stay I'll chase the rainblown fears away
We'll shine like the morning and sin in the sun oh if you stay
We'll be the wild ones running with the dogs today
We'll be the wild ones running with the dogs today

Sunday, July 24, 2011

Britpop and suede

Introduced by my besttie --I start listening to Suede and fall in love with this band immediately.  I still remember during my high school time, i use to listen those kind of bands --like oasis, but not Suede. Forgive my late awareness of such a good band. Thanks to my besttie, i didn't miss them after all. So i download all their albums including the Dog Man Star--an well-known masterpiece of them. Actually I think all their albums are great.  Anyway, their songs lead me to  learn them more:

   Suede are an English alternative rock band. Formed in London in 1989, the group's most prominent early line-up featured singer Brett Anderson, guitarist Bernard Butler, bass player Mat Osman and drummer Simon Gilbert. By 1992, Suede were hailed as "The Best New Band in Britain", and attracted much attention from the British music press. The following year their glam rock-inspired debut album, Suede, went to the top of the charts and became the fastest-selling debut album in almost ten years, helping kick-start the Britpop movement. However, the band's lush follow-up, Dog Man Star (1994), saw Suede distance themselves from their Britpop peers. Although it is often regarded as the band's masterpiece, the recording sessions for Dog Man Star were fraught with difficulty, and ended with Butler departing the band after heated arguments with Anderson.

   Britpop is a subgenre of alternative rock that originated in the United Kingdom. Britpop emerged from the British independent music scene of the early 1990s and was characterised by bands influenced by British guitar pop music of the 1960s and 1970s. The movement developed as a reaction against various musical and cultural trends in the late 1980s and early 1990s, particularly the grunge phenomenon from the United States. In the wake of the musical invasion into the United Kingdom of American grunge bands, new British groups such as Suede and Blur launched the movement by positioning themselves as opposing musical forces, referencing British guitar music of the past and writing about uniquely British topics and concerns. These bands were soon joined by others including Oasis, Pulp, Supergrass, Sleeper and Elastica

  A lot of homework need to do now ,start from my suede "beautiful ones" .

 

Saturday, December 4, 2010

浅谈J2me游戏如何快速移植到Android


--------转帖
前言

小白:老大,你让做的三个J2me游戏搞定了,请看DEMO
老大:恩,不错,小白,你知道Android这个平台吧?
小白:恩,听过。听说和J2ME有很多共同点。
老大:(一阵奸笑)很多共同点是吧?
小白:恩。
老大:那好,你把这几个J2ME游戏给我移植到Android上去。
小白:“……”

很多J2ME开发者可能都会遇到这样的临时性需求。其实J2ME程序往Android移植,并不是特别麻烦。
经过一番认真学习,小白开始整理起了笔记……

   高级UI界面

       J2ME的高级用户界面比较鸡肋,在现在大多数的应用里都看不到,多数稍微复杂点的界面都是手工画,或是用一些开源的高级UI库,但Android则不同,它的UI实用、方便,而且很美观,基本无需改动且定制方便。

一 设备差异

       虽说普通的手机性能越来越高,屏幕也越来越大,但平均而言,运行J2ME的手机从性能和屏幕分辨率及附属功能来说不及Android手机。拿入门的HTC G1来说,CPU528MHz,屏幕为3.17英寸触摸屏、HVGA 480×320像素,192MB RAM256MB ROM。所以从J2ME移植到Android的程序可以暂时不考虑性能问题。
       但要充分发挥Android手机的特点。要注意一下几点:
比如应用UI的布局可以更加自由,输入更加灵活,网络应用注意发挥3GWIFI的速度优势。
游戏要注意可适当的用效率换效果,可增加动画、音效、背景音乐的质量,图片元素的大小,发挥高分辨率手机的优势,强大的运算能力可以让开发人员编写基于OpenGL3D游戏,可以用一些吃CPU但效果不错的开发包,如Box2D仿真物理引擎开发包。
可以结合GPS定位、重力感应、话筒、指南针、触笔的压力感应等等让游戏的效果更加逼真。

  J2MEAndroid系统的常用类、方法对比

J2MEAndroid系统的常用类、方法对比

J2ME系统
Android系统
入口程序
MIDlet
Activity
图片类
Image
Image.createImage(path);
BitMap
BitmapFactory.decodeResource(getResources(),R.drawable.map0);
画笔
Graphics
Canvas
绘画
Displayable
View
按键
keyPressed()
keyRepeated()
keyReleased()
onKeyDown()
onKeyUp()
onTracKballEvent()
触笔
pointerPressed(),
pointerReleased(),
pointerDragged()
onTouchEvent()
打印信息
System.out.printlt()
Log
生命周期-开始
startApp(),活动状态,启动时调用,初始化。
onCreate(),返回时也会调用此方法。
onCreate()后调用onStart()
onStart()后调用onResume()
生命周期-暂停
PauseApp(),暂停状态,如来电时,调用该接口。
onPause()
生命周期-销毁
destroyApp(),销毁状态,退出时调用。
onStop(),程序不可见时调用onDestroy(),程序销毁时调用
刷新
高级UI组件由内部刷新实现。
低级UI,canvas中通过调用线程结合repaint()来刷新,让线程不断循环
高级UIHandler类通过消息的机制刷新
onDraw()刷新接口
低级UI开发者用线程控制更新,在lockCanvas()unlockCanvasAndPost()方法之间绘制
数据存储
Record Management System (RMS)
SQLite数据库
SharedPreferences
可绘区域
int clipX = g.getClipX(); 
int clipY = g.getClipY(); 
int clipW = g.getClipWidth(); 
int clipH = g.getClipHeight(); 
g.clipRect(x, y, width, height); 
g.setClip(clipX, clipY, clipW, clipH);
canvas.save();
canvas.clipRect(x,y,x+width, y+height); 
cavnas.resave();
游戏中清屏
paint.setStyle(Style.FILL);
canvas.drawRect(new Rect(0, 0, getWidth(), getHeight()), paint);
canvas.drawColor(Color.BLACK);
游戏开发包
javax.microedition.lcdui.game
GameCanvas
Layer
LayerManager
Sprite
TiledLayer
无专门针对游戏的开发包,可以直接拿来主义,将J2ME的开发包稍作修改
音效
Player s =Manager.createPlayer(InputStream);
s.prepare(); //创建
s.start();//播放
s.stop();//暂停
s.stop();//关闭
s.release();//释放  
MediaPlayer类处理背景音乐
SoundPool类处理一些简单的音效
全屏
CanvasSetFullScreenMode()
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
获得屏幕尺寸
Canvas类的getHeight()getWidth()
Display d = getWindowManager().getDefaultDisplay();
 screenWidth = d.getWidth();
 screenHeight = d.getHeight();
双缓冲
Image bufImage=Image.createImage(bufWidth, bufHeight);
Graphics bufGraphics=bufImage.getGraphics();
Bitmap carBuffer = Bitmap.createBitmap(bufWidth, bufHeight, Bitmap.Config.ARGB_4444); 
Canvas carGp = new Canvas(carBuffer);





      
   开始移植

       小白找到Android中对应的J2ME相关的替代类和替代方法后,开始噼里啪啦的改代码了。没过多久,首个俄罗斯方块算是移植成功。当他开始移植下一款游戏时,发现又要重复的改那些代码……
       “可不可以减少代码的改动呢?小白问自己。可否用Android的相关代码构造一些和J2me里功能类似的代码呢?

       原则:尽量少改动J2ME项目的代码。用Android中对应的类改写成J2ME中的方法和类,减少以后移植的工作量,甚至实现无缝移植。

       “或许我可以构造一个名为MIDlet实为Activity的类,这样J2me中的入口类就不用改动了
Activity类改装的MIDlet类:
public abstract class MIDlet extends Activity { 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
startApp(); 
public abstract void destroyApp(boolean unconditional); 
public String getAppProperty(String key) { 
return null; 
public abstract void startApp(); 
public void notifyDestroyed() { 
public void notifyPaused() {} 
public void pauseApp() {} 
public void platformRequest(String URL) {} 
public void resumeRequest() {} 

MIDlet类我们解决了,接下来就是非常重要的Canvas类了
J2me里的Canvas类相当于Android体系中的SurfaceView类,都是负责绘制显示界面的,游戏的大循环一半也在这两个类里实现,也就是都会实现Runnable类,更新逻辑和更新界面都在此类的大循环中处理。

Graphics类在J2me里负责绘图和排版样式等。
我们可以用Android里的Canvas类和Paint类共同组合一个Android里的Graphics类,如Graphics类的构造函数可这样定义:
public Graphics(Bitmap bitmap) {    
    this.bitmap = bitmap;    
    this.canvas = new Canvas(bitmap);    
    this.canvas.clipRect(0, 0, bitmap.getWidth(), bitmap.getHeight());    
    this.canvas.save(Canvas.CLIP_SAVE_FLAG);    
    this.paint = new Paint();    
    this.clip = canvas.getClipBounds();    
Graphics里可以设置居中方式,在Android体系里我们用Paint类来实现相同的效果,例如:
public void setAlign(int align)    
    {    
        if(LEFT == align    
                ||(Graphics.LEFT | Graphics.TOP) == align    
                ||(Graphics.LEFT | Graphics.BOTTOM) == align)    
        {    
            paint.setTextAlign(Align.LEFT);     
        }else if(HCENTER == align    
                ||(Graphics.HCENTER|Graphics.TOP) == align)    
        {    
            paint.setTextAlign(Align.CENTER);     
        }else if(RIGHT == align    
                ||(Graphics.RIGHT | Graphics.TOP) == align)    
        {    
            paint.setTextAlign(Align.RIGHT);    
        }    
}   

所有的绘制方法也同样沿用J2me中的方法名,用Android体系的代码完成方法体,达到无缝移植。以绘制、填充矩形为例:
public void fillArc(int x,int y,int width,int height, int startAngle,int arcAngle) {    
paint.setStyle(Style.FILL);    
    canvas.drawArc(new RectF(x,y,width,height), startAngle, arcAngle, true, paint);    
}       
public void drawArc(int x,int y,int width,int height, int startAngle,int arcAngle)  {    
    paint.setStyle(Style.STROKE);    
    canvas.drawArc(new RectF(x,y,width,height), startAngle, arcAngle, true, paint);    
}  

再来说说按键处理:
大体思路就是获取Android中的按键消息后,修改封装一下,转换成J2me的键值和事件,然后传递给显示层。

先定义出J2me中的键值:
public class GameCanvas extends Screen {    
    public static final int UP = 1;    
    public static final int DOWN = 6;    
    public static final int LEFT = 2;    
    public static final int RIGHT = 5;    
    public static final int FIRE = 8;    
        
    public static final int GAME_A = 9;    
    public static final int GAME_B = 10;    
    public static final int GAME_C = 11;    
    public static final int GAME_D = 12;    
        
    public static final int KEY_NUM0 = 48;    
    public static final int KEY_NUM1 = 49;    
    public static final int KEY_NUM2 = 50;    
    public static final int KEY_NUM3 = 51;    
    public static final int KEY_NUM4 = 52;    
    public static final int KEY_NUM5 = 53;    
    public static final int KEY_NUM6 = 54;    
    public static final int KEY_NUM7 = 55;    
    public static final int KEY_NUM8 = 56;    
    public static final int KEY_NUM9 = 57;    
    public static final int KEY_STAR = 42;    
    public static final int KEY_POUND = 35;    
}  
经过中间一个转换方法:
       public int keyCode4J2me = 0;
       public int keyAction4J2me = 0;
       public void changeToJ2meKey(int keyCode, KeyEvent e) {
              if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                     keyCode4J2me = GameCanvas.DOWN;
                     keyAction4J2me = GameCanvas.DOWN;
              } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
                     keyCode4J2me = GameCanvas.LEFT;
                     keyAction4J2me = GameCanvas.LEFT;
              } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                     keyCode4J2me = GameCanvas.RIGHT;
                     keyAction4J2me = GameCanvas.RIGHT;
              } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
                     keyCode4J2me = GameCanvas.FIRE;
                     keyAction4J2me = GameCanvas.FIRE;
              } else if (keyCode == KeyEvent.KEYCODE_0) {
                     keyCode4J2me = GameCanvas.KEY_NUM0;
              } else if (keyCode == KeyEvent.KEYCODE_1) {
                     keyCode4J2me = GameCanvas.KEY_NUM1;
              } else if (keyCode == KeyEvent.KEYCODE_2) {
                     keyCode4J2me = GameCanvas.KEY_NUM2;
              }
       }

转换成J2me的按键处理体系,转去调用J2me原生的keyReleased方法:
public boolean onKeyUp(int keyCode, KeyEvent e) {    
    changeToJ2meKey (keyCode,e);    
    keyReleased(keyActual);    
    return true;    

其他的字体类、颜色类、等等都可以按此方法无缝移植。
Font字体类用Android中的FontMetrics重写。
Graphics类中的setColor(int rgb)以及setColor(int r,int g,int b)方法,则可以修改Graphics类中Paint的颜色。如:
public void setColor(int r,int g,int b) {     
    int argb = (0xff000000)+(r<<16)+(g<<8)+b;    
    paint.setColor(argb);    

       小白心想:或许我还可以用Android中的Canvas类改写一个J2me中的Graphics类,用Android中的Bitmap改装一个J2me中的Image……然后把J2me游戏开发包javax.microedition.lcdui.game包里的GameCanvas类,Layer类,LayerManager类,Sprite类,TiledLayer类直接拿来用。嗯嗯,几乎不用改动原来的J2me代码了。第一个移植任务花费了一个周,以后一天就能移植一个小游戏啦。哈哈哈。
      
      
   后记

       小白:老大,游戏移植好了,请验收一下吧。
       老大:…………动作很快嘛,我看看代码,恩……代码封装的不错,一会来我办公室,谈谈你转正的事。
       小白:多谢老大。
       老大:普通的程序员会熟练的使用轮子,优秀的程序员要学会自己造轮子!
       小白:恩,我记住了。

Sunday, November 28, 2010

What is BossaNova

“Bossa”这个字源自于巴西里约热内卢的俚语,它指的是不受拘束的精明聪慧、和才华特出之类的意思。再加上葡萄牙文的Nova,取其 “新”的意义。所以,Bossa Nova就可以直接解释为无拘无束且极富创意的新音乐。它属于Latin Jazz,即融合巴西流行音乐风格(Samba)的爵士乐。是曼波(Mambo)音乐与冷爵士融合的结果,同时也吸取了一些桑巴(Samba)音乐的特点。它的音响效果不喧闹,给人的感觉像是呢喃细语。它的旋律性不 强,而是强调和声、节奏、旋律的整体效果。可是在一些爵士乐历史介绍中,Bossa Nova往往被忽略了。因为 Bossa Nova并非是纯正的美国纽奥良Jazz,而是所谓的“舶来品”。其实这是很不公平的,Bossa Nova自50年代末期在巴西兴起,并成为50、60年代巴西新流行音乐的代名词。1959年法国拍了一部电影,《黑人奥非尔(BLACK ORPHEUS) 》,夺得当年奥斯卡最佳外语片奖。片中浓厚的Bossa Nova配乐,引发一些美国爵士乐手对巴西音乐的好奇与探索。次中音萨克斯风手STAN GATZ因此特地远赴巴西里约热内卢,找 ANTONIO CAROLS JOBIM合作专辑。GATZ邀请JOBIM跟JOAO GILBERD夫妇一起到美国录制《The Girl From Ipnema》,JOAO自弹自唱了葡萄牙文版而英文版就由JOAO的太太ASTURD GILBERD演唱。配上 GATZ超棒的萨克斯风演奏,果然掀起一阵BOSSA NOVA热浪。跟传统南美及拉丁音乐不一样的是Bossa Nova不像森巴或伦巴舞曲一样节奏强烈且煽情,以巧妙的省略音符加上切分音效果,结合拉丁节奏的动感,结构上和美国西岸酷派爵士乐风格有相似,因此它有 着南美音乐的热情风味却多了慵懒及轻松,宛如千面女郎,有清晨的清新,午后的慵懒,夜晚的深情及子夜的忧郁 ……Bossa Nova就是何时听都很棒的音乐!

Saturday, November 20, 2010

A big present from China

This morning , I received a big surprise from my dear friend. All the snacks I used to eat in Beijing.HaHa.I love my friend.

Tuesday, November 16, 2010

Eat Pray Love

  I first heard it in the last episode of Big Bang.Then I found it on Wiki.It is about One Woman's Search for Everything Across Italy, India and Indonesia.It is a memoir of the American Author Elizabeth Gilbert.Also,it has been filmed on this Augest 31,acted by Julia Roberts.I like the tailer and maybe I will read the book first.

Eat, Pray, Love

Saturday, November 6, 2010

Fireflies for penny and sheldon

 I love this piece of video
http://www.youtube.com/watch?v=gcSlotYqa_Y&feature=fvw