XtGem Forum catalog
logo

Chatbox|Admin nhận làm wap/web, giá cả thương lượng... Thông tin admin tại mỗi bài viết.
Home · Bang hội ·
* Đăng Nhập hoặc Đăng Kí
để sử dụng hết chức năng của diễn đàn.
Hi, Khách!
HomeBang hội » Thủ thuật » Nokia s40 » Điều khiển giữ phím mượt mà trên Canvas
Xuống dưới » Điều khiển giữ phím mượt mà trên Canvas
avatar by Pham_loi Pham_loi
Chức vụ:
04:31:21, 06-07-2016

Có bạn hỏi sao tớ dùng hàm keyRepeated() để điều khiển nhân vật nó chậm và giật thế? Tớ phải làm gì?
Câu trả lời hay nhất dó là "giật thì bạn đừng dùng nữa!"
trol tí thôi chứ cái này đơn giản hãy dùng 1 boolean kiểm tra nếu đã bỏ tay ra tức là không còn giữ nữa :D
code:
<?php
import javax
.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class 
Midlet extends MIDlet
{
  public Display d Display.getDisplay(this);
  public void startApp()
  {
    myCanvas cv = new myCanvas();
    new Thread(cv) . start();
    d.setCurrent(cv);
  }
  public void pauseApp()
  {
  }
  public void destroyApp(boolean thongchetbocapvang)
  {
  }
}
class 
myCanvas extends Canvas implements Runnable
{
  private boolean danggiuphim;
  private int xykeycodewh;
  public myCanvas()
  {
    setFullScreenMode(true);
    h getHeight();
    w getWidth();
    x 2;
    y 2;
  }
  private void move()
  {
    switch (keycode)
    {
    case -1:
      y 3;
      break;
    case -2:
      y 3;
      break;
    case -3:
      x 3;
      break;
    case -4:
      x 3;
      break;
    }
  }
  public void paint(Graphics g)
  {
    g.setColor(0);
    g.fillRect(00wh);
    g.setColor(0xff0000);
    g.drawString((danggiuphim "Anh đang sờ chỗ" String.valueOf(keycode) : "Sao anh không sờ em?"), xyGraphics.HCENTER Graphics.BASELINE);
  }
  public void keyPressed(int keycode)
  {
    this.keycode keycode;
    danggiuphim true;
  }
  public void keyReleased(int keycode)
  {
    danggiuphim false;
  }
  public void run()
  {
    while (true)
    {
      if (danggiuphimmove();
      repaint();
      try
      
{
        Thread.sleep(30L);
      }
      catch(Exception ass)
      {
      }
    }
  }
}
?>

Copy code

Code điều khiển trong game team cũng tương tự. Mình định mod chạy nhanh NRO mà máy yếu sinh lí decom không nổi! Ai có thích vọoc mà máy khỏe thì làm nhé cứ mò theo cm.j[4, cm.j[6, cm.h[4, cm,h[6 là mod 1bước 1km ngay :-D dưới đây là bộ khung code điều khiển trong game Ngọc Rồng onl:
<?php
import javax
.microedition.lcdui.Canvas;
public abstract class 
cn extends Canvas implements Runnable
{
  public static boolean aJ;
  public cn()
  {
    setFullScreenMode(true);
  }
  public final void n()
  {
    new Thread(this) . start();
  }
  public int getHeight()
  {
    return -1;
  }
  public int getWidth()
  {
    return -1;
  }
  public final int p()
  {
    int i1;
    return (i1 super.getWidth()) / dr.b   (i1 dr.== 1);
  }
  public final int q()
  {
    int i1;
    return (i1 super.getHeight()) / dr.b   (i1 dr.== 1);
  }
  public final void pointerDragged(int i1int i2)
  {
    a(i1i2);
  }
  public final void pointerPressed(int i1int i2)
  {
    b(i1i2);
  }
  public final void pointerReleased(int i1int i2)
  {
    c(i1i2);
  }
  public abstract void a(int i1int i2);
  public abstract void b(int i1int i2);
  public abstract void c(int i1int i2);
  public abstract void c();
  public void run()
  {
    aJ true;
    while (aJ)
    {
      c();
      repaint();
      serviceRepaints();
      try
      
{
        Thread.sleep(5);
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
    }
  }
}
final class 
cm extends cn implements c
{
  public static booleanh;
  public static booleanj;
  static
  
{
    h = new boolean[14;
    j = new boolean[14;
  }
  public final void keyPressed(int i)
  {
    d(i);
  }
  private static void d(int i)
  {
    switch (i)
    {
    case 42:
      j[10 = true;
      h[10 = true;
      return;
    case 35:
      j[11 = true;
      h[11 = true;
      return;
    case -5:
      case 10:
      j[5 = true;
      h[5 = true;
      return;
      //keyOK
    case -38:
      case -1:
      j[2 = true;
      h[2 = true;
      return;
    case -39:
      case -2:
      j[8 = true;
      h[8 = true;
      return;
    case -3:
      j[4 = true;
      h[4 = true;
      return;
    case -4:
      j[6 = true;
      h[6 = true;
      return;
    }
  }
  public final void keyReleased(int i)
  {
    e(i);
  }
  private static void e(int i)
  {
    switch (i)
    {
    case 42:
      j[10 = false;
      return;
    case 35:
      j[11 = false;
      return;
    case -5:
      case 10:
      j[5 = false;
      return;
    case -38:
      case -1:
      j[2 = false;
      return;
    case -39:
      case -2:
      j[8 = false;
      return;
    case -3:
      j[4 = false;
      return;
    case -4:
      j[6 = false;
      return;
    }
  }
  public final void paint(Graphics G)
  {
  }
}
?>

Copy code

Tải xuống Vidugiuphim.zip (5.00 KB)
Nguồn: wtai


↓ Tập tin đính kèm ↓


Vui lòng Đăng Nhập để có thể tải file
Vidugiuphim.zip
Thể loại: application/zip
Dung lượng: 5KB

Like: 0
Lên trên  Tổng số: 1







Trực Tuyến: Khách: 1
Diễn đàn teen Việt Nam
CopyRight 2014