Skip to content

Instantly share code, notes, and snippets.

@Vavius
Vavius / gist:5964336
Created July 10, 2013 08:05
Another variant of TouchHandler. Sends touch events to all props under touch location. Also, it supports perspective 3d-view camera for layer. SwallowTouch method is designed to send cancel events to all touched props except the passed one. Used when we touched button and scrolled away to cancel button selected state.
--------------------------------------------------------------------------------
-- Event handler when you touch a layer.
-- @param e Event object
--------------------------------------------------------------------------------
local TMP_TABLE = {}
function TouchHandler:onTouch(e)
if not self.touchLayer.touchEnabled then
return
end
@Vavius
Vavius / Flower label blurry text workaround
Created August 1, 2013 16:04
Workaround for blurry text in MOAI when Viewport scale is different from device screen resolution.
-- Label will create a bigger sized font and scale it down
-- if view size is less than screen size.
function Label:init(text, width, height, font, textSize)
DisplayObject.init(self)
local scale = math.min(M.getContentScale())
-- do not apply scale fix to Bitmap fonts
if type(font) == "string" then
local fileBase, fileExt = Resources.extractFileExtension(font)
if fileExt == ".fnt" then scale = 1 end
@Vavius
Vavius / gist:8451928
Created January 16, 2014 09:09
Moai new GC related crash sample. Create a local prop (it will be collected on the first step!) and set its index or invoke any other method that calls ScheduleUpdate(). Crash in DepNodeUpdate when trying to access EVENT_UPDATE listener.
----------------------------------------------------------------
-- Copyright (c) 2010-2011 Zipline Games, Inc.
-- All Rights Reserved.
-- http://getmoai.com
----------------------------------------------------------------
MOAISim.openWindow ( "test", 320, 480 )
viewport = MOAIViewport.new ()
viewport:setSize ( 320, 480 )
@Vavius
Vavius / gist:8585062
Created January 23, 2014 19:21
Moai mesh vs props performance test
MOAISim.openWindow ( "test", 1536, 2048 )
viewport = MOAIViewport.new ()
viewport:setSize ( 1536, 2048 )
viewport:setScale ( 1536, 2048 )
layerMesh = MOAILayer.new ()
layerMesh:setViewport ( viewport )
layerMesh:setSortMode ( MOAILayer.SORT_NONE )
//----------------------------------------------------------------//
void MOAITouchSensor::HandleEvent ( ZLStream& eventStream ) {
u32 eventType = eventStream.Read < u32 >( 0 );
if ( eventType == TOUCH_CANCEL ) {
this->Clear ();
if ( this->mCallback && this->mAcceptCancel ) {
MOAISim.openWindow ( "test", 1536, 2048 )
viewport = MOAIViewport.new ()
viewport:setSize ( 1536, 2048 )
viewport:setScale ( 1536, 2048 )
layerMesh = MOAILayer.new ()
layerMesh:setViewport ( viewport )
layerMesh:setSortMode ( MOAILayer.SORT_NONE )
--------------------------------------------------------------------------------
-- src/layout/quest_dialog.lua
--
-- WARNING: Do not edit!
-- This file is auto generated, all changes will be lost.
--------------------------------------------------------------------------------
local Button = Gui.Button
local Sprite = Display.Sprite
local Group = Display.Group
local Label = Display.Label
--------------------------------------------------------------------------------
-- JsonStorageEngine.lua
--
-- Store lua tables as json documents
--------------------------------------------------------------------------------
local JsonStorageEngine = {}
JsonStorageEngine.DOCUMENTS_DIR = MOAIEnvironment.documentDirectory or 'docs'
TracebackHandler = function(err)
local err = err or ''
local task = MOAIHttpTask.new()
local str = STP and STP.stacktrace() or debug.traceback()
local trace = err .. '\n' .. str
local params = {}
params.err = err
params.error = trace
params.os = MOAIEnvironment.osBrand
#include <moai-core/host.h>
#include <moai-android/moaiext-jni.h>
#include <jni.h>
#include "game_script.h"
#include "crash_handler.h"
void AKURunGame () {
AKULoadFuncFromBuffer ( crash_handler, crash_handler_SIZE, AKU_DATA_STRING, AKU_DATA_ZIPPED );
AKUCallFunc ();