`
rensanning
  • 浏览: 3522867 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:37664
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:605012
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:678968
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:87846
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:400338
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69209
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:90824
社区版块
存档分类
最新评论

Titanium的2D游戏引擎模块-QuickTiGame2d

阅读更多
What is QuickTiGame2d?

QuickTiGame2d is a 2-dimensional game engine module for Titanium Mobile that provides quick and easy api to create casual 2d games on Titanium. QuickTiGame2d runs much faster on mobile devices because it is based on OpenGL ES: the industry-standard graphics library on embedded systems. Currently QuickTiGame2d supports both iOS and Android.

http://code.google.com/p/quicktigame2d/

An addictive Whac-A-Mol like game "Kawaz-tan tataki!" is included as example of QuickTiGame2d.


What does it look like?
// Obtain game module
var quicktigame2d = require('com.googlecode.quicktigame2d');

// Create view for your game.
var game = quicktigame2d.createGameView();

// Frame rate can be changed (fps can not be changed after the game is loaded)
game.fps = 30;

// Initialize your game scene
var scene = quicktigame2d.createScene();
game.pushScene(scene);

// Create your sprites and add them to the scene
var background = quicktigame2d.createSprite(
  {image:'background.png', width:640, height:960, x:0, y:0}
);

var sprite = quicktigame2d.createSprite({image:'ball.png'});

// Sprite sheet is supported
var tiles = quicktigame2d.createSpriteSheet(
  {image:'tiles.png', width:32, height:32}
);

// Add sprites to the scene
scene.add(background);
scene.add(sprite);
scene.add(tiles);

// Set sprite opacity to 50%
sprite.alpha = 0.5;

// Rotate sprite in 30 degree
sprite.rotate(30);

// Scale up the sprite by twice
sprite.scale(2);

// Z-order can be changed
background.z = 0;
sprite.z     = 1;

// Called when the game is loaded
game.addEventListener('onload', function(e) {
  Ti.API.info("your game is loaded");

  // Change position of your sprite
  sprite.x = game.screen.width  * 0.5;
  sprite.y = game.screen.height * 0.5;

  // Select first frame of sprite sheet
  tiles.frame = 0;

  // sprite sheet animation is also supported
  tiles.animate([0, 1, 2], 500);

  game.start();
}

// Called when the game enters frame
game.addEventListener('enterframe', function(e) {
  // Change position of your sprite
  sprite.x = sprite.x + 1;

  // Rotate your sprite
  sprite.rotate(sprite.angle + 6);
}

// Called when user taps screen
game.addEventListener('singletap', function(e) {
  // Note that Ti.UI.View returns non-retina coordinate even on retina devices,
  // so we have to take the scale into account to process touch event.
  var scale = game.screen.width / game.width;

  // Change position of your sprite
  sprite.x = e.x * scale;
  sprite.y = e.y * scale;

}


Performance Test

  • 大小: 135.4 KB
  • 大小: 104.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics