cocos2dx CCArray of sprites - cocos2d-x

I am working on cocos2dx. I am fetching images from facebook for the Leaderboard.
When images fetched from facebook I used them as CCtexture but I have lot of images so, each time I don't want to create object of CCTexture.
I used CCArray but it also create each object of CCTexture.
CCArray* ccArray = new CCArray();
CCObject* ccText = NULL;
CCTexture2D *ccTexture = dynamic_cast<CCTexture2D*>(ccText);
CCTexture2D * ccTexture0 = new CCTexture2D();
CCTexture2D * ccTexture1 = new CCTexture2D();
CCARRAY_FOREACH(ccArray, ccText)
{
ccTexture=new CCTexture2D();
ccArray->addObject(ccTexture);
ccArray->addObject(ccTexture0);
ccArray->addObject(ccTexture1);
}

Related

Get physical screen(display) resolution. Windows Store App

I need current display resolution. How can i get this? I know about Window.Current.Bounds, but application can worked in windows mode.
what do you mean VisibleBounds is not working on Deskptop?
I tried in my win10 UWP program, it works fine. I can get my desktop resotion like below:
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
var size = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);
Besides, if you are using DX in store app, you can create an IDXGIFactory object and use it to enumerate the available adapters. Then call IDXGIOutput::GetDisplayModeList to retrieve an array of DXGI_MODE_DESC structures and the number of elements in the array. Each DXGI_MODE_DESC structure represents a valid display mode for the output. e.g.:
UINT numModes = 0;
DXGI_MODE_DESC* displayModes = NULL;
DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT;
// Get the number of elements
hr = pOutput->GetDisplayModeList( format, 0, &numModes, NULL);
displayModes = new DXGI_MODE_DESC[numModes];
// Get the list
hr = pOutput->GetDisplayModeList( format, 0, &numModes, displayModes);
Please let me know if you need further information.

If two sprites are visible, do something (AS3)

I'm creating a memory like game. I built all the desktop, the cards generation. I now have two cards of each.
I'm trying to do the pairs delete system.
my function to show the color to find looks like this :
private function onClick(e:MouseEvent):void
{
if (vueDos)
{
vueDos = !vueDos;
faceCarte = new Sprite();
faceCarte.graphics.lineStyle(2,0x000000,.5);
faceCarte.graphics.beginFill(clr);
faceCarte.graphics.drawRoundRect(8,8,this.width - 16, this.height - 16, 10,10);
faceCarte.graphics.endFill();
var _t:TextField = new TextField();
_t.selectable = false;
_t.antiAliasType = "advanced";
_t.autoSize = "left";
_t.defaultTextFormat= new TextFormat(maFont.fontName,24,0x000000);
_t.text = couleur;
_t.x = (this.width - _t.width)/2
_t.y = (this.height - _t.height) >> 1;
faceCarte.addChild(_t);
faceCarte.cacheAsBitmap = true;
this.addChild(faceCarte);
}
if(!vueDos)
}
Does it exist a function wich see if the color of the card is visible (faceCarte), and limit the visibles carte to two then removeChild faceCart.
Thank you in advance
You have to make such a function yourself. It'll be better to assign a couleur property to the card itself, instead of putting it into the TextField and forgetting. This way you'll be able to open first card, get that property, then open second card and compare that one's property with what you received, if match, both cards will be removed.

Taking a screenshot of a page in InDesign Extension Builder

For my current assignment I need to make an extension for Adobe InDesign using Adobe Creative Suit Extension Builder and Flash Builder. I guess this is more of a question for ones that know Extension Builder and InDesign API.
The point of this extension is to load some data and send some data to a server. I need to make a screenshot of a page, then send it in jpg to a server. But, there are no (or at least i couldnt find any) ways to create a bitmap(to cast it on a object seems impossible, because this Objects are just Objects, and not DisplayObjects).
I managed to silently export pages as jpegs, now I'm thinking about loading them and sending but that will require building an AIR app to handle it all, so this will be a bit bulky.
So to sum up the question, how to take a screencapture of all elements on a page in InDesign using CS Ext.Builder?
what is the problem with export to JPG ? You can choose to export the page or the objects themselves.
Here is a snippet I wrote in a recent project. Hope it helps.
public static function getFilePath():String {
var app:com.adobe.indesign.Application = InDesign.app;
var sel:* = app.selection, oldResolution:Number, oldColorSpace:JpegColorSpaceEnum, groupItems:Array = [], i:int = 0, n:int = sel.length;
if (!sel || !n )
{
Alert.show("Pas de selection !", "title", Alert.OK, Sprite(mx.core.Application.application));
return "";
}
for ( i = 0 ; i < n ; i ++ )
{
groupItems [ groupItems.length ] = sel[i];
}
sel = ( sel.length > 1 )? app.activeDocument.groups.add ( sel ) : sel[0] ;
var tempFolder:File = File.createTempDirectory();
AppModel.getInstance().jpgFolder = tempFolder;
var jpgFile:File = new File ();
jpgFile.nativePath = tempFolder.nativePath + "/temp.jpg";
oldResolution = app.jpegExportPreferences.exportResolution;
app.jpegExportPreferences.exportResolution = 72;
oldColorSpace = app.jpegExportPreferences.jpegColorSpace;
app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY;
sel.exportFile ( ExportFormat.jpg, jpgFile );
app.jpegExportPreferences.jpegColorSpace = oldColorSpace;
app.jpegExportPreferences.exportResolution = oldResolution;
if ( sel is Group )
{
sel.ungroup();
app.select ( groupItems );
}
return jpgFile.nativePath;
}

Clone an instance of a class (Display Object)

I have a collection of movieclips, I would like to create a clone (a new instance) of a instance everytime I create a new object.
For example
var s:Star = new Star(); // star-shaped movielcip
addChild(s);
// then I want to duplicate an instance of s and add it beside s
For an example like above, it's simple enough to create a new instance with a different name and just add it to the display list. But I have a list of objects I would like to clone as a group...?
Belowed code is very famous for cloning the objects. It's deepest and dynamic.
...
function clone(orjObj:Object):Object {
var copyObj:ByteArray = new ByteArray();
copyObj.writeObject(orjObj);
copyObj.position = 0;
return(copyObj.readObject());
}
var s2:Star = clone(s);
s2.x = s.x + s.width;
s2.y = s.y;
addChild(s2);
moses' solution is correct. What is the purpose of the clone, where you wouldn't need to know the name of the clone to reference it?
One option is you could create an array to store your references in so you don't need to explicitly name them. Using moses' code...
var clones:Array = new Array();
for each (var star:Star in [s, s2, s3, s4, s5]) {
clones.push(clone(star));
}
trace(clones.length); // 5
This will result in an array that holds 5 cloned stars. It takes the least amount of code but it's up to you to make sure you know which star is which afterwards.

How write the values from the database into an array in Flash Builder 4

I want to display multiple images and when rollover above it i must get a tooltips (names). The same names are in the database mySQL. Naturally, to tooltips displayed without delay, preferably immediately put all the names from the database into an array and then manipulate them. Tell me please what I do wrong?
Php class to connect database:
public function getDataMean($id,$dir_id) {
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci';");
mysql_select_db(DATABASE_NAME);
$query = "SELECT name FROM files WHERE id='".$id."' AND dir_id='".$dir_id."'";
$result = mysql_query($query);
return $result;
}
FB4 code:
public var Names:Array = new Array();
public var textName:String;
protected function decks_clickHandler(event:MouseEvent):void
{
arrayOfNumber = new Array();
generateArray(minCount,maxCount);
randomize(arrayOfNumber);
var dir_id:int = 7;
card1.source = "http://***/gallery/7/"+String(arrayOfNumber[0])+".jpg";
card2.source = "http://***/gallery/7/"+String(arrayOfNumber[1])+".jpg";
card3.source = "http://***/gallery/7/"+String(arrayOfNumber[2])+".jpg";
for (var i:int=0; i<4; i++){
getDataMeanResult.token = authors.getDataMean(arrayOfNumber[i], dir_id);
Names[i] = getDataMeanResult.lastResult[0].name;
}
}
]]>
</fx:Script>
It's a bit hard to see from your code. But as I understood; you have some cards with in ID each, and you want to grab matching data from array when ever the user interacts with that card? - Correct?
If that is the case you properly want to use an associative array instead. In AS3 you use an instance of the Oject class as an associative array (yes that does seem a bit wierd). So maybe you should rewrite your code declaring Names as a Object instead of Array.
With that being said I can see one other problem with your code, you write Names[i] = ..., but you have not declared the size of the Array (or maybe that is what the generateArray function does?). Try using Names.push(getDataMeanResult.lastResult[0].name) instead.