How to get rid of image tearing d3d11? - directx

If I open my app in full screen, I get severe tears. In other games, even with vcync turned off, this is almost invisible. How can I achieve the same effect without vsync? cube example
DXGI_SWAP_CHAIN_DESC1 scd = {};
if (mIsGame)
{
scd.Width = RECT_WIDTH(mRect_Game);
scd.Height = RECT_HEIGHT(mRect_Game);
}
else
{
scd.Width = RECT_WIDTH(mRect_Editor);
scd.Height = RECT_HEIGHT(mRect_Editor);
}
scd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.SampleDesc.Count = 1;
scd.SampleDesc.Quality = 0;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.BufferCount = 1;
if (mIsGame)
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
FOG_TRACE(dxgiFactory2->CreateSwapChainForHwnd(mDevice, mHwnd, &scd, 0, 0, &mSwapChain1));
FOG_TRACE(mSwapChain1->QueryInterface(IID_PPV_ARGS(&mSwapChain)));
dxgiFactory2->Release();
if (mIsGame)
{
FOG_TRACE(mSwapChain1->SetFullscreenState(true, 0));
mFullScreen = true;
}

Related

How to add watermark to aspose pdf and word that contain table

I generate a Aspose.Generate.Pdf file and then add a Aspose.Pdf.Generator.Tableto it by following method. but when I add watermark to this pdf file, it covers by created table:
public static BasketResult<string> ExportDataTableToPdf(DataTable inputDataTable, string CaptionFilename)
{
List<DataColumn> listDataColumns = GetDataColumns(inputDataTable, CaptionFilename);
BasketResult<string> returnResult = new BasketResult<string>();
String rtnPathFile = String.Empty;
int rowCount = inputDataTable.Rows.Count;
if (rowCount <= 1000)
{
try
{
string dataDir = Settings.TempPath;
if (!Directory.Exists(dataDir))
Directory.CreateDirectory(dataDir);
Pdf pdfConv = new Pdf();
pdfConv.IsRightToLeft = true;
Aspose.Pdf.Generator.Section mainSection = pdfConv.Sections.Add();
mainSection.TextInfo.IsRightToLeft = true;
mainSection.IsLandscape = true;
mainSection.TextInfo.Alignment = AlignmentType.Right;
// header definition begin
Aspose.Pdf.Generator.HeaderFooter header = new Aspose.Pdf.Generator.HeaderFooter(mainSection);
mainSection.EvenHeader = header;
mainSection.OddHeader = header;
header.Margin.Top = 50;
Aspose.Pdf.Generator.Table headerTable = new Aspose.Pdf.Generator.Table();
header.Paragraphs.Add(headerTable);
headerTable.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);
headerTable.Alignment = AlignmentType.Right;
headerTable.DefaultColumnWidth = "80";
headerTable.FixedHeight = 30;
Aspose.Pdf.Generator.Row headerRow = headerTable.Rows.Add();
headerRow.BackgroundColor = new Aspose.Pdf.Generator.Color("#D3DFEE");
int index = 0;
listDataColumns.Reverse();
foreach (DataColumn column in listDataColumns)
{
string cellText = column.Caption;
headerRow.Cells.Add(cellText);
headerRow.Cells[index].DefaultCellTextInfo.FontName = "Tahoma";
headerRow.Cells[index].DefaultCellTextInfo.IsRightToLeft = true;
headerRow.Cells[index].VerticalAlignment = VerticalAlignmentType.Center;
headerRow.Cells[index++].Alignment = AlignmentType.Center;
}
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Tables.Table wordTable = ImportTableFromDataTable(builder, inputDataTable,
CaptionFilename, true);
string columnWidths = "";
for (int j = 0; j < wordTable.FirstRow.Count; j++)
{
columnWidths = columnWidths + "80 ";
}
Aspose.Pdf.Generator.Table table = new Aspose.Pdf.Generator.Table();
mainSection.Paragraphs.Add(table);
table.ColumnWidths = columnWidths;
table.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);
table.Alignment = AlignmentType.Right;
//fill table
for (int i = 1; i < wordTable.Rows.Count; i++)
{
Aspose.Pdf.Generator.Row row = table.Rows.Add();
row.BackgroundColor = i % 2 == 0
? new Aspose.Pdf.Generator.Color("#D3DFEE")
: new Aspose.Pdf.Generator.Color("#FFFFFF");
var wordTableRow = wordTable.Rows[i];
//fill columns from end to begin because table is left to right
for (int c = wordTable.FirstRow.Count - 1; c >= 0; c--)
{
var cellValue = wordTableRow.ChildNodes[c];
string cellText = cellValue.GetText();
row.Cells.Add(cellText);
}
//set style to every cell
for (int c = 0; c < wordTable.FirstRow.Count; c++)
{
row.Cells[c].DefaultCellTextInfo.FontName = "Tahoma";
row.Cells[c].DefaultCellTextInfo.IsRightToLeft = true;
row.Cells[c].VerticalAlignment = VerticalAlignmentType.Center;
row.Cells[c].Alignment = AlignmentType.Center;
}
}
pdfConv.SetUnicode();
rtnPathFile = Helper.GetTempFile() + ".pdf";
string fileName = Helper.GetFileNameFromFilePath(rtnPathFile);
pdfConv = AddPdfWatermark(pdfConv);
pdfConv.Save(dataDir + fileName);
returnResult.Result.Add(rtnPathFile);
returnResult.IsSuccess = true;
}
catch (Exception ex)
{
rtnPathFile = String.Empty;
returnResult.IsSuccess = false;
returnResult.Result.Add(rtnPathFile);
returnResult.persianErrorMessages.Add(Messages.Err_InvalidFilePath);
}
}
else
{
returnResult.IsSuccess = false;
returnResult.Result.Add(rtnPathFile);
returnResult.persianErrorMessages.Add(Messages.Err_CreateFile);
}
return returnResult;
}
and AddPdfWatermerk method is :
private static Pdf AddPdfWatermark(Aspose.Pdf.Generator.Pdf pdfConv)
{
try
{
// Create FloatingBox with x as width and y as height
Aspose.Pdf.Generator.FloatingBox background = new Aspose.Pdf.Generator.FloatingBox(); // width, height
Aspose.Pdf.Generator.Image backImage = new Aspose.Pdf.Generator.Image();
string path = HttpContext.Current.Server.MapPath("~/images/PrivateExcelBackGround.png");
byte[] bgBuffer = File.ReadAllBytes(path);
MemoryStream streamBack = new MemoryStream(bgBuffer, false);
backImage.ImageInfo.ImageStream = streamBack;
background.Paragraphs.Add(backImage);
background.ZIndex = 1000;
pdfConv.Watermarks.Add(background);
pdfConv.IsWatermarkOnTop = false;
return pdfConv;
}
catch
{
return pdfConv;
}
}
I tried stamp instead of watermark, but table masks it too.
in aspose.words.document file I have a problem too, in word file with mentioned table,watermark added correctly but when a colored alternate table rows, watermark covered by colorful rows.
You are using an out-dated version of Aspose.PDF API. Kindly upgrade to Aspose.PDF for .NET 18.1, which includes more features and bug fixes. You can add an image stamp by using below code snippet in your environment.
// Open document
Document pdfDocument = new Document(dataDir+ "AddImageStamp.pdf");
// Create image stamp
ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");
imageStamp.Background = true;
imageStamp.XIndent = 100;
imageStamp.YIndent = 100;
imageStamp.Height = 300;
imageStamp.Width = 300;
imageStamp.Rotate = Rotation.on270;
imageStamp.Opacity = 0.5;
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(imageStamp);
dataDir = dataDir + "AddImageStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
ImageStamp class provides the properties necessary for creating an image-based stamp, such as height, width, opacity etc. You may visit Adding stamp in a PDF file for further information on this topic. In case you notice any problem with the file generated by using this code, please get back to us with source and generated file so that we may proceed to help you out.
I work with Aspose as Developer Evangelist.

iPad's mobile safari crashing on canvas-based game (easeljs, soundjs, preloadjs)

I've done quite a bit of searching, so please forgive me if this has been asked before (I couldn't seem to find the right phrasing, if this is the case).
I have converted a quiz game from Flash to html5 using the createjs suite of libraries, and it is functioning suitably well on android devices and iPhones (tested on an iPhone 4s and 5c). However, it appears to be crashing on an iPad whenever I try and load it.
As I am packaging the game in cocoonjs for mobile deployment, I first thought the issue lied somewhere in the conversion process, but the same issue is encountered when I visit the URL on an iPad, leading me to believe the issue must be somewhere in my code.
The code itself uses a loadManifest to preload the image assets for the game and the opening audio file. There are approximately 170 assets loaded in this queue. The files are loaded using an onLoad method from the body tag and call loadFiles(), which looks like this (truncated for the multitude of image assets loaded in the manifest):
var queue = new createjs.LoadQueue(true);
var manifest = [
{id:"gameintro", src:"audio/intro.mp3"},
{src:"images/Path.png"},
...
{src:"images/owl.png"}
];
queue.loadManifest(manifest);
queue.setMaxConnections(5);
queue.addEventListener("complete", loadComplete);
function loadAll() {
document.getElementById('canvas').style.backgroundImage="url('images/splash.png')";
canvas = document.getElementById('canvas');
canvas.height = H;
canvas.width = W;
stage = new createjs.Stage("canvas");
var loadingText = new createjs.Text("Loading...", "bold 30px Arial", "#9d3202");
loadingText.x = 350;
loadingText.y = 585;
loadingText.textBaseline = "alphabetic";
stage.addChild(loadingText);
stage.update();
while (manifest.length > 0) {
loadAnother();
}
//console.log('done');
}
function loadAnother() {
// Get the next manifest item, and load it
var item = manifest.shift();
queue.loadFile(item);
// If we have no more items, disable the UI.
if (manifest.length == 0) {
//do nothing
}
}
function loadComplete()
{
stage.removeAllChildren();
var clickToPlay = new createjs.Bitmap("images/clicktoplay.png");
clickToPlay.x = 350;
clickToPlay.y = 565;
clickToPlay.textBaseline = "alphabetic";
stage.addChild(clickToPlay);
stage.update();
canvas.addEventListener("click", function(event) {
event.target.removeEventListener(event.type, arguments.callee);
createjs.Sound.registerSound({id:"gameintro", src:"audio/intro.mp3"});
createjs.Sound.addEventListener("fileload", function(event){
event.target.removeEventListener(event.type, arguments.callee);
init();
});
});
}
loadAll();
};
The init function that runs after this loads the remaining audio files (of which there are many ~ 160 mp3's) and starts the opening animation. The code for that section is as follows:
function init(){
createjs.Sound.registerSound({id:"meintroduction", src:"audio/Mentor/ME1.mp3"});
...
createjs.Sound.registerSound({id:"jennyfalse3", src:"audio/Pirate_Jenny/PJE10.mp3"});
document.getElementById('canvas').style.background="#B5D7ED";
canvas = document.getElementById('canvas');
canvas.height = H;
canvas.width = W;
stage = new createjs.Stage("canvas");
//add path
path = new createjs.Bitmap("images/Path.png");
path.x = 0;
path.y = 0;
stage.addChild(path);
//add sun
sun = new createjs.Bitmap("images/sun.png");
sun.x = 800;
sun.y = 600;
stage.addChild(sun);
//add pinkcloud
pinkcloud = new createjs.Bitmap("images/pinkcloud.png");
pinkcloud.x = -4;
pinkcloud.y = 150;
stage.addChild(pinkcloud);
//add bluecloud
bluecloud = new createjs.Bitmap("images/bluecloud.png");
bluecloud.x = -4;
bluecloud.y = 250;
stage.addChild(bluecloud);
//add farisland
farisland = new createjs.Bitmap("images/farisland.png");
farisland.x = 600;
farisland.y = 180;
stage.addChild(farisland);
//add backwave
backwave = new createjs.Bitmap("images/backwave.png");
backwave.x = -4;
backwave.y = 420;
stage.addChild(backwave);
//shark
shark = new createjs.Bitmap("images/shark.png");
shark.x = 900;
shark.y = 600;
stage.addChild(shark);
//fish3
fish3 = new createjs.Bitmap("images/fish3.png");
fish3.x = 800;
fish3.y = 600;
stage.addChild(fish3);
//add middlewave
middlewave = new createjs.Bitmap("images/middlewave.png");
middlewave.x = -800;
middlewave.y = 450;
stage.addChild(middlewave);
//add ship
pirateship = new createjs.Bitmap("images/pirateship.png");
pirateship.x = -500;
pirateship.y = 400;//445x384
pirateship.regX = 445/2;
pirateship.regY = 384/2;
stage.addChild(pirateship);
//fish1
fish1 = new createjs.Bitmap("images/fish1.png");
fish1.x = 800;
fish1.y = 600;
stage.addChild(fish1);
//fish1
fish2 = new createjs.Bitmap("images/fish2.png");
fish2.x = 900;
fish2.y = 700;
stage.addChild(fish2);
//add frontwave
frontwave = new createjs.Bitmap("images/frontwave.png");
frontwave.x = -4;
frontwave.y = 500;
stage.addChild(frontwave);
//bird
bird1 = new createjs.Bitmap("images/bird.png");
bird1.x = 0;
bird1.y = 0;
bird1.scaleX = -1;
stage.addChild(bird1);
bird2 = new createjs.Bitmap("images/bird.png");
bird2.x = 800;
bird2.y = 0;
stage.addChild(bird2);
//add island
island = new createjs.Bitmap("images/island.png");
island.x = 800;
island.y = 200;
stage.addChild(island);
//add setsail
setsail = new createjs.Bitmap("images/Setsail.png");
setsail.x = -358;
setsail.y = 80;
createjs.Tween.get(setsail).to({alpha: 0,},0);
stage.addChild(setsail);
setsail1 = new createjs.Bitmap("images/Setsail.png");
setsail1.x = 350;
setsail1.y = 80;
//add butwatchout
butwatchout = new createjs.Bitmap("images/Butwatchout.png");
butwatchout.x = -358;
butwatchout.y = 300;
createjs.Tween.get(butwatchout).to({alpha: 0,},0);
//stage.addChild(butwatchout);
butwatchout1 = new createjs.Bitmap("images/Butwatchout.png");
butwatchout1.x = 200;
butwatchout1.y = 300;
setTimeout(function(){createjs.Sound.play("gameintro");},1500);
fn = createjs.Ticker.on("tick", tick);
createjs.Ticker.setFPS(80);
createjs.Ticker.addEventListener("tick", stage );
}
The ticker then uses some basic rotations and tweens to move things about, and also employs some alpha filters to manage the transparency of certain assets (like the front wave on the ship). After all this is finished, the user then progresses into the actual game, which uses some very basic createjs.Bitmaps to add the elements to the stage, along with Sound.play and some SpriteSheets for the rudimentary animations like blinking and mouth-movements for the quizzers. However, the whole thing doesn't make it past the opening sequence on an iPad.
If anyone could take a look (amateurgamingleague.com/pirates/english) and give me a bit of insight as to where I'm messing up, out would be greatly appreciated!!
Thank you!
I have had the same crashes on Ipad (2). It even did delete all session cookies and my users where logged out...
The problem is the amount of sounds you're preloading (or how big they are, not sure). Change your code to not preload so many audio anymore, and load them on demand (when user clicks on something) if possible. I also needed to start the game with a click/touch/user event before any sound could be played.
I got the same issue.
Try to use slash before the directory like
var manifest = [
{id:"gameintro", src:"/audio/intro.mp3"},
{src:"/images/Path.png"},
...
{src:"/images/owl.png"}
];

Need code to make animation to stop

Trying to stop this animation on frame 109 in as2. Any help in what I need to ad to get this to stop. It is a confetti animation.
cnfNumber = 85;
var cnfs:Array = new Array("cnf", "cnf2", "cnf3","cnf4","cnf5")
for (i=0; i<cnfNumber; i++) {
newCnf = _root[cnfs[random(cnfs.length)]].duplicateMovieClip("snow"+i, i);
newCnf._x = Math.random()*Stage.width;
newCnf._y = -Math.random()*300;
newCnf.maxCnfSpeed = Math.random()*4;
newCnf.wind = Math.random()*6;
newCnf._xscale = newCnf._yscale = newCnf.alpha = Math.random()*65+35
newCnf.onEnterFrame = function() {
this._rotation -= this.maxCnfSpeed+1;
if(this._y>Stage.height || this._x>Stage.width || this._x<0){
this._y = -Math.random()*300;
this._x = Math.random()*Stage.width;
} else {
this._y += this.maxCnfSpeed+2;
this._x += this.wind-4;
}
this._alpha = this.alpha;
};
}
Why not just do this:
newCnf._xscale = newCnf._yscale = newCnf.alpha = Math.random()*65+35
newCnf.frameCount = 0;
newCnf.onEnterFrame = function() {
if(this.frameCount<109) {
this._rotation -= this.maxCnfSpeed+1;
if(this._y>Stage.height || this._x>Stage.width || this._x<0){
this._y = -Math.random()*300;
this._x = Math.random()*Stage.width;
} else {
this._y += this.maxCnfSpeed+2;
this._x += this.wind-4;
}
this._alpha = this.alpha;
this.frameCount++;
} else {
this.onEnterFrame = null;
}
};
I haven't worked in Actionscript in a while, so the this.onEnterFrame = null may not be quite correct, but it's not strictly necessary; it just keeps the confetti from checking the frame number and bailing out every frame once it's done animating.
If you want the confetti to disappear rather than freezing in place, unload it instead of clearing its onEnterFrame. I don't remember the function that does that off the top of my head, but the documentation for duplicateMovieClip should have a link to it.
(I won't ask why you're still using AS2.)

Change colors in devexpress charts

I am drawing a pie chart using Devexpress in my MVC project.
While doing it by default my chart generated with three colors, as below
but my client is not satisfied, with the colors of it and wanted me to change them which match with our application background, so please help me, how to do this.
Thanks in advance.
Here is my code.
settings.Name = "chart";
settings.Width = 600;
settings.Height = 250;
settings.BorderOptions.Visible = false;
Series series1 = new Series("Type", DevExpress.XtraCharts.ViewType.Pie3D);
settings.Series.Add(series1);
series1.ArgumentScaleType = ScaleType.Qualitative;
series1.ArgumentDataMember = "ClassName";
series1.ValueScaleType = ScaleType.Numerical;
series1.ValueDataMembers.AddRange(new string[] { "PercentageValues" });
series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;
series1.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
series1.LegendPointOptions.ValueNumericOptions.Precision = 0;
series1.Label.ResolveOverlappingMode = ResolveOverlappingMode.Default;
series1.Label.Visible = false;
Please refer the following code. I have successfully implemented the same for giving custom color for rangebar. I guess it will work for your case also
settings.CustomDrawSeriesPoint = (s, ev) =>
{
BarDrawOptions drawOptions = ev.SeriesDrawOptions as BarDrawOptions;
if (drawOptions == null)
return;
Color colorInTarget = Color.Blue;
double x = ev.SeriesPoint.Values[0];
double y = ev.SeriesPoint.Values[1];
if (x == 0)
{ //Do starting
colorInTarget = Color.FromArgb(159,125, 189);
}
else{
//Red - price Increase
// Green price Decrease
if (y > previousYValue)
{
colorInTarget = Color.Red; ;
}
else
{
colorInTarget = Color.Green;
}
}
previousYValue = y;
drawOptions.Color = colorInTarget;
drawOptions.FillStyle.FillMode = FillMode.Solid;
drawOptions.Border.Color = Color.Transparent;
};
you can set the theme and palette properties of the chart control. follow the links below to devexpress documentation. although the examples refers to winform application they are still avaliable in asp.net mvc controls.
http://documentation.devexpress.com/#WindowsForms/CustomDocument7433
http://documentation.devexpress.com/#WindowsForms/CustomDocument5538
// Define the chart's appearance and palette.
barChart.AppearanceName = "Dark";
barChart.PaletteName = "Opulent";
private List<StudentClass.ChartsPointsSummary> GetStudentSummaryResults()
{
var StudentId = Convert.ToInt32(Request.Params["StudentID"]);
var StudentDetailsP = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var Presents = StudentDetailsP.Select(p => new { p.Months, p.Presents});
var CountsP = StudentDetailsP.Count();
List<StudentClass.ChartsPointsSummary> MT = new List<StudentClass.ChartsPointsSummary>();
foreach (var ab in Presents)
{
MT.Add(new StudentClass.ChartsPointsSummary { PresentSummaryX = ab.Months, PresentSummaryY = Convert.ToInt32(ab.Presents) });
}
var StudentDetailsA = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var Absents = StudentDetailsP.Select(p => new { p.Months, p.Absents });
var CountsA = StudentDetailsA.Count();
foreach (var ab in Absents)
{
MT.Add(new StudentClass.ChartsPointsSummary { AbsentSummaryX = ab.Months, AbsentSummaryY = Convert.ToInt32(ab.Absents) });
}
var StudentDetailsL = CtxSM.SMISGet_StudentAttendanceDetailsByStudentId(StudentId, SessionDataManager.SessionData.LoginUserId, SessionDataManager.SessionData.AcademicYearID, SessionDataManager.SessionData.BusinessUnitId, ref outError).ToList();
var CountL = StudentDetailsL.Count();
var Leaves = StudentDetailsP.Select(p => new { p.Months, p.Leaves });
foreach (var ab in Leaves)
{
MT.Add(new StudentClass.ChartsPointsSummary { LeaveSummaryX = ab.Months, LeaveSummaryY = Convert.ToInt32(ab.Leaves) });
}
return MT;
}
#Html.DevExpress().Chart(settings =>
{
settings.Name = "SummaryDetailsById";
settings.Width = 1032;
settings.Height = 250;
Series chartSeries = new Series("Presents", DevExpress.XtraCharts.ViewType.Bar);
chartSeries.ArgumentDataMember = "PresentSummaryX";
chartSeries.ValueDataMembers[0] = "PresentSummaryY";
settings.Series.Add(chartSeries);
Series chartSeries2 = new Series("Absents", DevExpress.XtraCharts.ViewType.Bar);
chartSeries2.ArgumentDataMember = "AbsentSummaryX";
chartSeries2.ValueDataMembers[0] = "AbsentSummaryY";
settings.Series.Add(chartSeries2);
Series chartSeries3 = new Series("Leaves", DevExpress.XtraCharts.ViewType.Bar);
chartSeries3.ArgumentDataMember = "LeaveSummaryX";
chartSeries3.ValueDataMembers[0] = "LeaveSummaryY";
settings.Series.Add(chartSeries3);
settings.CrosshairEnabled = DefaultBoolean.Default;
settings.BackColor = System.Drawing.Color.Transparent;
settings.BorderOptions.Visibility = DefaultBoolean.True;
settings.Titles.Add(new ChartTitle()
{
Text = "Student Attendance Summary"
});
XYDiagram diagram = ((XYDiagram)settings.Diagram);
diagram.AxisX.Label.Angle = -30;
diagram.AxisY.Interlaced = true;
}).Bind(Model).GetHtml()

Actionscript 2: Tween running extremely slow

I am using the following code to tween an movieclip once _global.choiceMade equals 1...
onClipEvent (load) {
import mx.transitions.Tween;
import mx.transitions.easing.*;
}
onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
}
}
This is contained within each frame of the main timeline. The first time it runs fine but on the next frame it runs incredibly slow (takes about 12 seconds not 0.5 and is very choppy), if I then return to the first frame and run it again now this time it is extremely slow.
I can't work out why its doing this my CPU stays around 6-15% while its running so it can't be too demanding.
Updated to show rest of my code:
On main timeline have a frame each containing a movieclip. On the timeline of each of these movieclips contains:
//tint an object with a color just like Effect panel
//r, g, b between 0 and 255; amount between 0 and 100
Color.prototype.setTint = function(r, g, b, amount) {
var percent = 100-amount;
var trans = new Object();
trans.ra = trans.ga=trans.ba=percent;
var ratio = amount/100;
trans.rb = r*ratio;
trans.gb = g*ratio;
trans.bb = b*ratio;
this.setTransform(trans);
};//Robert Penner June 2001 - http://www.robertpenner.com
MovieClip.prototype.scaleXY = function(to){
this.onEnterFrame = function(){
this._alpha = to-(to-this._alpha)/1.2;
if(this._alpha > to-1 && this._alpha < to+1){
this._alpha = to;
delete this.onEnterFrame
}
}
}
scoreUpdated = 0;
Answer = 1;
_global.choiceMade = 0;
Buttons = new Array(this.buttonHolder.True, this.buttonHolder.False);
Answers = new Array(this.Correct, this.Wrong);
for (i=0; i<Answers.length; i++) {
Answers[i]._alpha = 0;
}
for (b=0; b<Buttons.length; b++) {
Buttons[b].thisValue = b;
}
In this movieclip there are two movieclip buttons (True and False) containing this code:
onClipEvent (enterFrame) {
this.onRollOver = function() {
this.gotoAndStop("over");
};
this.onRollOut = function() {
this.gotoAndStop("up");
};
this.onPress = function() {
this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
this.gotoAndStop("up");
};
this.onRelease = function() {
this.gotoAndStop("down");
whichChoice = this;
_global.choiceMade = 1;
counter = 0;
};
if (_global.choiceMade == 1) {
this.enabled = false;
this._parent.scoreNow = _global.score;
this._parent.scoreOutOf = (this._parent._parent._currentframe)- 1 + ( _global.choiceMade);
if (thisValue == this._parent._parent.Answer && whichChoice == this) {
myColor = new Color(this);
myColor.setTint(0,204,0,13);
this._parent._parent.Answers[0]._alpha = 100;
this._parent._parent.Answers[0].scaleXY(100);
this.tick.swapDepths(1000);
if (counter == 0) {
_global.score++;
counter++;
}
}
else if (thisValue == this._parent._parent.Answer) {
myColor = new Color(this);
myColor.setTint(0,204,0,13);
this.tick.swapDepths(1000);
}
else if (whichChoice == this) {
this._parent._parent.Answers[1]._alpha = 100;
this._parent._parent.Answers[1].scaleXY(100);
myColor = new Color(this);
myColor.setTint(255,0,0,13);
this.cross.swapDepths(1000);
}
else {
myColor = new Color(this);
myColor.setTint(255,0,0,13);
myColor.setTint(255,0,0,13);
this.cross.swapDepths(1000);
}
}
}
The script at the top is on a movieclip these buttons are contained in called buttonHolder which does what it says, and tweens the buttons across the screen to reveal a next button once an answer is chosen.
From what I can see, as long as you have choiceMade == 1 you create a new effect! which is not ok. because in 1 sec at 15 fps you will have 15 tweens running :(
try yo set choiceMade = 0 or somehting else than 1
onClipEvent (enterFrame)
{
if (_global.choiceMade == 1)
{
_global.choiceMade = -1;
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
}
}
Without seeing the rest of your code it's hard to see exactly what's going on. But it looks like you never change choiceMade and it continuously recreates the tween.
onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
_global.choiceMade = 0;
}
}

Resources