绘制精灵的边界框(drawing bounding box of sprite)
在cocos2d-x中,如何显示作为该层子元素的所有精灵的边界框?
这是我的出发点:
void MyLayer::draw() { // super draw CCLayer::draw(); // Iterate through all nodes of this layer for ( CCNode* node = ??? ) { // Make sure the node is a CCSprite if ( node == CCSprite ??? ) { CCSprite* sprite = (CCSprite*) node; ccDrawRect( sprite->boundingBox() ??? ); } } }
In cocos2d-x, how can I display the bounding box for all sprites that are children of this layer?
Here's my starting point:
void MyLayer::draw() { // super draw CCLayer::draw(); // Iterate through all nodes of this layer for ( CCNode* node = ??? ) { // Make sure the node is a CCSprite if ( node == CCSprite ??? ) { CCSprite* sprite = (CCSprite*) node; ccDrawRect( sprite->boundingBox() ??? ); } } }
原文:https://stackoverflow.com/questions/12698247
更新时间:2021-09-14 07:09
最满意答案
如果你想使用AJAX来做,那么让你的PHP脚本返回POSTed值并在AJAX请求的成功处理程序中获取它。 为了使成功处理程序能够更改
testNumber
的值,必须在function otvaranje
之外声明该变量。以下是必要的修改(还要注意我添加的评论):
PHP
if(isset($_POST['broj'])){ $br = $_POST['broj']; $file = fopen($br . "broj.txt", "w"); fclose($file); // Just output the value and exit // If there is business logic doing something with // $br, then move this after that code. // But remember to only do this if the script was // called with POST, otherwise the initial request // wouldn't work anymore. print $br; exit; }
JavaScript的
var testNumber = "<?php echo $br; ?>"; function slanje(br){ $.ajax({ type: 'POST', dataType: 'html', data: { 'broj' : br, }, success: function(data) { // called when the request succeeded testNumber = data; } }); } function otvaranje(id, broj){ slanje(broj); // move outside: var testNumber = <?php echo $br; ?> + ""; // rest of function content }
If you want to do it using AJAX, then let your PHP script return the POSTed value and grab it in the success handler of the AJAX request. For the success handler to be able to change the value of
testNumber
, the variable has to be declared outside offunction otvaranje
.Here are the necessary modifications (also take note of the comments I added):
PHP
if(isset($_POST['broj'])){ $br = $_POST['broj']; $file = fopen($br . "broj.txt", "w"); fclose($file); // Just output the value and exit // If there is business logic doing something with // $br, then move this after that code. // But remember to only do this if the script was // called with POST, otherwise the initial request // wouldn't work anymore. print $br; exit; }
JavaScript
var testNumber = "<?php echo $br; ?>"; function slanje(br){ $.ajax({ type: 'POST', dataType: 'html', data: { 'broj' : br, }, success: function(data) { // called when the request succeeded testNumber = data; } }); } function otvaranje(id, broj){ slanje(broj); // move outside: var testNumber = <?php echo $br; ?> + ""; // rest of function content }
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
使用ajax将数组发布到PHP(Posting Array to PHP using ajax)[2022-04-12]
注意:您的代码输出array()主要原因是您在发送/处理异步(AJAX)请求之前重定向客户端 基本上移动window.location = "AddtoDatabase.php"; 到成功回调,就像下面提到的那样。 第一个问题:您应该使用对象字面值(〜= assoc array in php),而不是使用数组。 为此,请更改此位: var dataArray = new Array(7);//<== NEVER do this again, btw dataArray[0]= "routeID:" + ro ... -
在PHP中回显时,在Javascript函数中不起作用的新行(New lines not working in Javascript function when echoing in PHP)[2024-02-28]
您只需将表达式放在标记之间:{{ x.info.text }}
)。 这是一个有效的例子。 我删除了PHP标记并使用纯文本进行演示: text: 'line 1\nline 2' 顺便说一句 - 您可以用white-space: pre;替换PRE标签white-space: pre; css风格。 function MyCtrl($scope) { $scope.environme ... -