示例类:
class Example{
public static $ONE = [1,'one'];
public static $TWO = [2,'two'];
public static $THREE = [3,'three'];
public static function test(){
// manually created array
$arr = [
self::$ONE,
self::$TWO,
self::$THREE
];
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在PHP中获取类静态成员变量数组而不像示例中那样手动创建它?
我正在为pixijs库准备externs文件以使用闭包编译器.到目前为止我唯一的问题是使用自定义对象参数.这是一个简短的例子:
pixi.js来源:
/**
* Set the style of the text
*
* @param [style] {object} The style parameters
* @param [style.font='bold 20pt Arial'] {string} The style and size of the font
* @param [style.fill='black'] {string|number} A canvas fillstyle that will be used on the text eg 'red', '#00FF00'
* @param [style.align='left'] {string} Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text
Run Code Online (Sandbox Code Playgroud)
闭包编译输出:
lib/pixi-externs.js:3266: WARNING - Parse error. invalid param name "style.font"
* @param [style.font='bold 20pt …Run Code Online (Sandbox Code Playgroud) 我正在为PIXI.js库准备externs.我收到以下警告:
js/Test.js:188: WARNING - Property position never defined on PIXI.Sprite
button.position.y = y;
Run Code Online (Sandbox Code Playgroud)
以下是相关的外部定义:
// UPDATE
/**
* @constructor
* @extends {PIXI.Container}
* @param {PIXI.Texture} texture
*/
PIXI.Sprite = function(texture){};
/**
* @constructor
* @extends {PIXI.DisplayObject}
*/
PIXI.Container = function(){};
/**
* @constructor
* @extends {PIXI.EventEmitter}
*/
PIXI.DisplayObject = function(){};
/**
* @type {PIXI.Point}
*/
PIXI.DisplayObject.position;
Run Code Online (Sandbox Code Playgroud)
仍然得到同样的警告.
我究竟做错了什么?
当我更换PIXI.DisplayObject.position;使用PIXI.DisplayObject.prototype.position;,似乎清除警告.
这是否意味着我应该始终明确SomeObject.prototype.prop而不是SomeObject.prop?
我收到这个警告:
WARNING - restricted index type
found : string
required: number
someArray[ index ].doSomething();
Run Code Online (Sandbox Code Playgroud)
这在闭包编译器升级到最新版本后发生.看起来封闭编译器不推荐使用数组的字符串类型索引.
这个问题的推荐解决方案是什么?
BTW.有没有办法禁用检查这些警告类型(我查看了CC标志列表,找不到任何东西)?
我创建了一个小型测试项目来复制问题.该项目仅包含pixi.min.js和index.html,其中包含此示例中的代码:
http://pixijs.github.io/examples/index.html?s=demos&f=interactivity.js&title=Interactivity
当我通过浏览器测试时按钮工作.它们也在intel-xdk emulate选项卡中工作.
但是当我转到test标签,推送文件,扫描二维码以打开iPhone上创建的应用程序时,按钮出现但触摸事件无法正常工作.
为什么触摸事件不会在iPhone上触发?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body style="margin:0; padding: 0; background: #333333;">
<script src="pixi.min.js"></script>
<script>
var renderer = PIXI.autoDetectRenderer(800, 600);
document.body.appendChild(renderer.view);
var stage = new PIXI.Container();
var textureButton = PIXI.Texture.fromImage('images/button.png');
var textureButtonDown = PIXI.Texture.fromImage('images/button.png');
var textureButtonOver = PIXI.Texture.fromImage('images/button2.png');
var buttons = [];
var buttonPositions = [
175, 75,
655, 75,
410, 325,
150, 465,
685, 445
];
var noop = function () {
//console.log('click');
};
for (var i …Run Code Online (Sandbox Code Playgroud) 我不确定如何清除此警告:
WARNING - actual parameter 1 of
CanvasRenderingContext2D.prototype.drawImage does not match formal parameter
found : Element
required: (HTMLCanvasElement|HTMLImageElement|HTMLVideoElement|null)
ctx.drawImage( poolCanvas, rect.x, rect.y );
Run Code Online (Sandbox Code Playgroud)
这是相关的代码:
var /** @type {HTMLCanvasElement|Element} */ poolCanvas = document.createElement('canvas');
var /** @type {CanvasRenderingContext2D} */ ctx;
...
ctx.drawImage( poolCanvas, rect.x, rect.y );
Run Code Online (Sandbox Code Playgroud)
我尝试了各种类型声明的组合,但无法摆脱此警告。
我在这里做错了什么?