loading animation through texturepacker in cocos2dx for windows phone - animation

Im running an animation using the following code
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("kid1.plist");
CCSpriteBatchNode *spritesheet = CCSpriteBatchNode::create("kid1.png");
this->addChild(spritesheet);
CCArray *kidframes = new CCArray;
for(int i=1; i<3; i++){
CCString *filename = CCString::createWithFormat("kid%d.png",i);
CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString());
kidframes->addObject(frame);
}
CCAnimation *runanim = CCAnimation::createWithSpriteFrames(kidframes, 0.1);
CCSprite *kiddo = CCSprite::createWithSpriteFrameName("kid2.png");
kiddo->setPositionX(100*setScreenX);
kiddo->setPositionY(100*setScreenY);
kiddo->setScaleX(setScreenX);
kiddo->setScaleY(setScreenY);
CCAction *action = CCRepeatForever::create(CCAnimate::create(runanim));
kiddo->runAction(action);
spritesheet->addChild(kiddo);
THIS ISNT WORKING ITS GIVING ME AN ERROR WHEN I ADD FRAMES TO KID FRAMES
CCAssert(m_uReference > 0, "reference count should greater than 0");
any help?

Here's something that we used to animate our Sprites.
CCAnimation *animation = CCAnimation::create();
animation->setDelayPerUnit(0.05f);
//Add the frames to the animation
string animationFramePrefix = "mySprite";
string animationFrames = "1,2,3,4,5,6,7,8,9";
char *strArr=new char[animationFrames.size()+1];
strArr[animationFrames.size()]=0;
memcpy(strArr,animationFrames.c_str(),animationFrames.size());
const char* p;
for (p = strtok(strArr, "," ); p; p = strtok( NULL, "," ))
{
string frameName = animationFramePrefix+"_"+p+".png";
CCSpriteFrame* sprite = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName.c_str());
animation->addSpriteFrame(sprite);
}
//initialize sprite with initial display frame
CCSprite *mySprite = CCSprite::createWithSpriteFrameName("mySprite_1.png");
//then use the animation when required!
CCAnimate *animationAction = CCAnimate::create(animation);
CCRepeatForever *repeatAction = CCRepeatForever::create(animationAction);
mySprite->runAction(repeatAction);

Try to change
CCArray *kidframes = new CCArray;
to
CCArray *kidframes = CCArray::create();

instead of new ccarray();
try create::ccarray();

Related

How to remove a selected part of an image in Flutter?

I want to send an image to backend, but before sending user can select some part of it. And I need to remove unwanted part. Below I attached some screenshots.
After three days of working on it I finally found out, how to work around.
So if it's not an eraser I'm just drawing as always but if an eraser I'm replacing Paint with shader wich is my image from background.
if (!_eraser) {
paint = new Paint()
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round
..color = selectedColor
..strokeWidth = strokeWidth;
} else {
final Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
..[10] = 1.0
..[15] = 2.0;
paint = new Paint()
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round
..shader = ImageShader(image, TileMode.repeated, TileMode.repeated, deviceTransform)
..strokeWidth = strokeWidth;
Painting Class
#override
void paint(Canvas canvas, Size size) {
canvas.drawImage(image, Offset.zero, new Paint());
for (int i = 0; i < pointsList.length - 1; i++) {
if (pointsList[i] != null && pointsList[i + 1] != null) {
canvas.drawLine(pointsList[i].points, pointsList[i + 1].points, pointsList[i].paint);
} else if (pointsList[i] != null && pointsList[i + 1] == null) {
offsetPoints.clear();
offsetPoints.add(pointsList[i].points);
offsetPoints.add(Offset(pointsList[i].points.dx + 0.1, pointsList[i].points.dy + 0.1));
canvas.drawCircle(pointsList[i].points, pointsList[i].paint.strokeWidth / 2, pointsList[i].paint);
}
}
}
If you want to crop the image basic on some user input that you already have, you could use the copyCrop function from the image library.

In UITextfield, When applying color using NSMutableAttributedString the color is not applied correctly when unfocusing

Using NSMutableAttributedString, I applied color for a specific character in a string using UITextfield. My Code:
uITextField = new UITextField(); uITextField.BackgroundColor = UIColor.LightGray;
uITextField.Frame = new CGRect(10, 150, 350, 40);
uITextField.Text = "Hai i am ________________";
uITextField.TextColor = UIColor.Green;
uITextField.EditingChanged += UITextField_EditingChanged;
private void UITextField_EditingChanged(object sender, EventArgs e)
{
var promptStringAttributes = new UIStringAttributes
{
ForegroundColor = UIColor.Red
};
var promptString = new NSMutableAttributedString(uITextField.Text);
char[] mText = uITextField.Text.ToCharArray();
Char prchar = '_';
for (int i = 0; i < mText.Length; i++)
{
if (!string.IsNullOrEmpty(uITextField.Text) && prchar == mText[i])
{
promptString.SetAttributes(promptStringAttributes.Dictionary, new NSRange(i, 1));
}
}
uITextField.AttributedText = promptString;
}
Initially, the text will be in Green color. See the below image:
After deleting the last character in the UItextfield, I will change the color of some character to red
The problem which I am facing is after unfocusing the UITextfield, the Red color is applied to all the character in the UITextField and the text color is not displayed correctly. Only the set attribute color is applied for all the character in the string. See the below image:
Please give a possible solution to restrict of applying the set attribute color for all the string when unfocusing the UITextField in xamarin iOS.
Improve your method
var promptStringAttributes_Red = new UIStringAttributes
{
ForegroundColor = UIColor.Red
};
var promptStringAttributes_Green = new UIStringAttributes
{
ForegroundColor = UIColor.Green
};
var promptString = new NSMutableAttributedString(uITextField.Text);
char[] mText = uITextField.Text.ToCharArray();
Char prchar = '_';
for (int i = 0; i < mText.Length; i++)
{
if (!string.IsNullOrEmpty(uITextField.Text) && mText[i] ==prchar)
{
promptString.SetAttributes(promptStringAttributes_Red.Dictionary, new NSRange(i, 1));
}
else
{
promptString.SetAttributes(promptStringAttributes_Green.Dictionary, new NSRange(i, 1));
}
}
uITextField.AttributedText = promptString;

Side of object flickers when the camera is rotated

Can someone explain why part of my model flickers black when a material canvas material is added to it and when the camera moves?
Here's a shot of it before an image is added:
And after when an image has been added and camera rotated:
Notice the black marks at the top. Is this to do with the material I'm using possibly? Here's how I apply it:
for(let i = 0; i < sidesModified.length; i++) {
let sideName = sidesModified[i];
let side = this.getSideInLayersObservable(view, sideName);
let maxAnisotropy = (this.scene && this.scene['renderer']) ? this.scene['renderer'].getMaxAnisotropy() : 2;
let canvasTexture = new THREE.CanvasTexture(ctx.canvas, THREE.UVMapping, this.scene.materials.wrapS, this.scene.materials.wrapT, THREE.LinearFilter, THREE.LinearMipMapLinearFilter, THREE.RGBAFormat, THREE.UnsignedByteType, maxAnisotropy);
for(let j = 0; j < side.length; j++) {
canvasTexture.wrapS = this.scene.materials.wrapS;
canvasTexture.wrapT = this.scene.materials.wrapT;
this._reverseSideIf(this.sceneName, view, sideName, canvasTexture);
this._drawImageOnCtx(side, j, object, ctx);
}
let materialIndex = this.getMaterialIndexForBag(this.sceneName, view, sideName);
let material = this._setupMaterial(canvasTexture);
if(this.sceneName === 'two-d-scene') {
if(view === 'outside') {
this.selectedBag[0].children[materialIndex].material = material;
} else {
this.selectedBag[1].children[materialIndex].material = material;
}
} else {
this.selectedBag.children[materialIndex].material = material
}
canvasTexture.needsUpdate = true;
}

When I create pdf with itextg from ListView only the same listview child appears

I am trying to create a pdf from listview items. This is my listview:
This is the result:
Below is my code:
ListView def = (ListView) findViewById(R.id.ist);
ListAdapter adapter = def.getAdapter();
int itemscount = adapter.getCount();
/*int itemsposition = adapter.getItem(position);*/
Toast.makeText(getApplicationContext(), itemscount + " temaxia", Toast.LENGTH_LONG).show();
int allitemsheight = 0;
List<Bitmap> bmps = new ArrayList<Bitmap>();
for (int i = 0; i < itemscount ; i++) {
View childView = adapter.getView(i, null, def);
/*View childView = def.getChildAt(1);*/
childView.measure(View.MeasureSpec.makeMeasureSpec(def.getWidth(),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView.layout(0, 0, childView.getMeasuredWidth(),
childView.getMeasuredHeight());
childView.setDrawingCacheEnabled(true);
childView.buildDrawingCache();
childView.getDrawingCache();
/*bmps.add(childView.getDrawingCache());
allitemsheight+=childView.getMeasuredHeight();*/
Bitmap bigbitmap = Bitmap.createBitmap(def.getMeasuredWidth(),
childView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas bigcanvas = new Canvas(bigbitmap);
def.draw(bigcanvas);
Paint paint = new Paint();
bigcanvas.drawBitmap(bigbitmap,0,childView.getMeasuredHeight(),paint);
bigbitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.scalePercent(45, 60);
myImg.setAlignment(Image.ALIGN_CENTER);
// add image to document
doc.add(myImg);
doc.add( new Paragraph());
}
I just cant find why it only gets childview in first position despite it is inside a for loop. Can anyone help me? Thanks.
I changed all the consept to: Create a big image from all childviews and then cut it to multiple pages A4 size.See below....NOTICE that first doc is never opened and never closed,but after creating image document is opened and closed properly ...............
File file = new File(dir, flname + ".pdf");
FileOutputStream fOut = new FileOutputStream(file);
FileOutputStream fOut2 = new FileOutputStream(file);
pdfWriter.getInstance(doc, fOut);
// open the document
/* doc.open();*/
ByteArrayOutputStream stream = new ByteArrayOutputStream();
//////////////////////
ListView def = (ListView) findViewById(R.id.ist);
ListAdapter adapter = def.getAdapter();
int itemscount = adapter.getCount();
/*int itemsposition = adapter.getItem(position);*/
Toast.makeText(getApplicationContext(), itemscount + " temaxia", Toast.LENGTH_LONG).show();
View childView =null;
int allitemsheight = 0;
List<Bitmap> bmps = new ArrayList<Bitmap>();
for (int i = 0; i < itemscount ; i++) {
childView = adapter.getView(i,null,def);
/*childView = def.getChildAt(i);*/
childView.measure(View.MeasureSpec.makeMeasureSpec(def.getWidth(),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView.layout(0, 0, childView.getMeasuredWidth(),
childView.getMeasuredHeight());
childView.setDrawingCacheEnabled(true);
childView.buildDrawingCache();
/*childView.getDrawingCache();*/
bmps.add(childView.getDrawingCache());
allitemsheight+=childView.getMeasuredHeight();
}
Bitmap bigbitmap = Bitmap.createBitmap(def.getMeasuredWidth(),
allitemsheight , Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
Canvas bigcanvas = new Canvas(bigbitmap);
for (int i = 0; i < bmps.size(); i++) {
Bitmap bmp = bmps.get(i);
bigcanvas.drawBitmap(bmp, 0, iHeight, paint);
/*bigcanvas.drawColor(Color.WHITE);
def.draw(bigcanvas);*/
iHeight+=bmp.getHeight();
bmp.recycle();
bmp=null;
}
bigbitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.scalePercent(45, 60);
myImg.setAlignment(Image.ALIGN_CENTER);
/*if(myImg.getWidth() >= doc.getPageSize().getWidth() || myImg.getHeight() >= doc.getPageSize().getHeight()){
myImg.scaleToFit(doc.getPageSize());
doc.newPage();
}
myImg.setAbsolutePosition((doc.getPageSize().getWidth() - myImg.getScaledWidth()) / BaseField.BORDER_WIDTH_MEDIUM, (doc.getPageSize().getHeight() - myImg.getScaledHeight()) / BaseField.BORDER_WIDTH_MEDIUM);
doc.add(myImg);
doc.add( new Paragraph());*/
///////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////
Document document = new Document();
PdfWriter pdfWriter2 = PdfWriter.getInstance(document, fOut2);
document.open();
PdfContentByte content = pdfWriter2.getDirectContent();
myImg.scaleAbsolute(PageSize.A4);
myImg.setAbsolutePosition(0, 0);
float width = PageSize.A4.getWidth();
float heightRatio = myImg.getHeight() * width / myImg.getWidth();
int nPages = (int) (heightRatio / PageSize.A4.getHeight());
float difference = heightRatio % PageSize.A4.getHeight();
while (nPages >= 0) {
document.newPage();
content.addImage(myImg, width, 0, 0, heightRatio, 0, -((--nPages * PageSize.A4.getHeight()) + difference));
}
document.close();
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
} finally {
/*doc.close();*/
}

How to properly fix contacts in SpriteKit?

I use this code and it has to work, but it doesn't:
static const uint32_t platformCategory = 0x1 << 1;
static const uint32_t playerCategory = 0x1 << 2;
Code of player:
self.player = [SKSpriteNode spriteNodeWithImageNamed:#"player"];
self.player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.size];
self.player.physicsBody.dynamic = false;
self.player.physicsBody.friction = 0;
self.player.physicsBody.usesPreciseCollisionDetection = true;
self.player.physicsBody.categoryBitMask = playerCategory;
self.player.physicsBody.collisionBitMask = platformCategory;
self.player.physicsBody.contactTestBitMask = platformCategory;
[self addChild:self.player];
And code of "platforms":
- (void)addPlatformRight {
int plType = arc4random()%3;
SKSpriteNode * platform = [SKSpriteNode spriteNodeWithImageNamed:[NSString stringWithFormat:#"platform%d", plType]];
platform.position = CGPointMake(self.frame.size.width+100, self.frame.size.height-200);
platform.size = CGSizeMake(platform.size.width*1.2, platform.size.height*2);
platform.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:platform.size];
platform.physicsBody.dynamic = false;
platform.physicsBody.friction = 0;
platform.physicsBody.usesPreciseCollisionDetection = true;
platform.physicsBody.categoryBitMask = platformCategory;
platform.physicsBody.contactTestBitMask = playerCategory;
platform.physicsBody.collisionBitMask = playerCategory;
[self addChild:platform];
[platform runAction:[SKAction sequence:#[[SKAction rotateByAngle:M_PI/4.0*8 duration:3], [SKAction removeFromParent]]]];
}
And
- (void)didBeginContact:(SKPhysicsContact *)contact {
NSLog(#"contact");
}
Unfortunately, this doesn't work. Are there any errors?
two overlapping non-dynamic bodies do not generate contact events, at least one of them has to be dynamic

Resources