I use some png sprites for my CCAnimation:
self.heroAnim = [CCAnimation animation];
for(int i = 1; i <= count; ++i) {
[self.heroAnim addFrameWithFilename:[NSString stringWithFormat:#"%#_%d_%d.png", _spriteName, currentLevel, i]];
}
self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:self.heroAnim restoreOriginalFrame:NO]];
but now I have to change scale of CCAnimation (about size*0.75) Can you get me some suggestion to realise it? I've got just separate png files for my CCAnimation. I don't want to resize sprite's files physically.
You can try to change scale property of the sprite, that you use to run this animation. Sprite should resize all the frames of your animation automatically.
Related
I want to load gif image in UIImageView. I've try to use it wih FLAnimatedImage but it not worked. I have taken imageview in storyboard and added gif to resources.
If you want to load gif image with UIImageView, I find one article that you can take a look:
https://montemagno.com/animated-gif-uiimageview-in-xamarinios/
If you try to create the gif using individual images, it will be easier, as you can see here. When you convert the native code from here to C#, you get this
UIImageView gifView = new UIImageView();
gifView.AnimationImages = new UIImage[] {
UIImage.FromBundle("Image1.png"),
UIImage.FromBundle("Image2.png"),
UIImage.FromBundle("Image3.png"),
UIImage.FromBundle("Image4.png")
};
gifView.AnimationRepeatCount = 0; // Repeat forever.
gifView.AnimationDuration = 1.0; // Every 1s.
gifView.StartAnimating();
gifView.View.Frame = new CoreGraphics.CGRect(0, 20, this.View.Bounds.Size.Width, 180); // size of the animation
this.View.AddSubview(gifView);
I am taking Pebble example of working with APNG and trying to mask it with transparent text, so bitmap will show only thru text, but no matter what mask/composite mode I try, bitmap is shown as black-and-white (original animation is in color and shows in color if I don't draw text)
Here's a sample code I use in callback SP for the layer that draws text:
//creating background and text
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, GRect(0, 0, 144, 168), 0, GCornerNone);
graphics_context_set_text_color(ctx, GColorWhite);
graphics_draw_text(ctx, "08:39", fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49), GRect(0,50,144,118), GTextOverflowModeFill, GTextAlignmentCenter, NULL);
//drawing bitmap (extracted from bitmap_sequence elsewhere)
graphics_context_set_compositing_mode(ctx, GCompOpClear);
graphics_draw_bitmap_in_rect(ctx, s_bitmap, GRect(0,0,144,168));
Any idea how to have actual color bitmap to show thru?
Ok, I finally managed it but not sure if this is the best way. I basically capture framebuffer of current layer and then loop thru every pixel, copying there source bitmap byte by byte, but only when white pixels are encountered:
GBitmap *fb = graphics_capture_frame_buffer_format(ctx, GBitmapFormat8Bit);
uint8_t *fb_data = gbitmap_get_data(fb);
uint8_t *anim_data = gbitmap_get_data(s_bitmap);
for (int i=0; i < 144*168; i++) {
if (fb_data[i] == 255) {
fb_data[i] = anim_data[i];
}
}
This can be optimized too.
I am trying to render 3D bar chart in SCNView using ScreenKit framework.
My rendering code is,
int height=10,y=0,x=0;
for (int i=0; i<10; i++) {
SCNBox *box1 = [SCNBox boxWithWidth:4 height:height length:2 chamferRadius:0];
boxNode1 = [SCNNode nodeWithGeometry:box1];
boxNode1.position = SCNVector3Make(x, y, 0);
SCNMaterial *material = [SCNMaterial material];
material.diffuse.contents = (NSColor *)[self.colorArray objectAtIndex:i%6];
material.specular.contents = [NSColor whiteColor];
material.shininess = 1.0;
box1.materials = #[material];
//boxNode1.transform = rot;
[scene.rootNode addChildNode:boxNode1];
x+=6;
height+=10;
y += 5 ;
}
I can render but while re-sizing the view the chart bars goes to the center of the view.
I need to render the chart, which cover the margins of the view and when Re-size it have to change accordingly. The image(s) below shows my problem.
Original Image:
Image where less stretching of both windows:
Can anyone please help me to fix the issue.
The the windows in the image that you had linked to in your original question was very stretched and that made it very hard to see what was going on. When I took that image and made the windows less stretched it was easier to have some idea of what is going on.
I think that you are seeing a general resizing issue. Either you are using springs and struts and have configured flexible margins on the left and right or you are using auto layout with a centered view with fixed width.
I assume that the red boxes that I have drawn in the image below is the bounds of your scene view in both these cases. You can easily see if this is the case by giving the scene view a different background color and resize it again.
My solution to your problem would be to change how your view resizes as the window resizes, to better meet your expectations.
I want to have a random sprite spawn and move across the screen.
I'm using CGRectIntersectsRect to detect collisions between the player and the randomly spawned sprites.
I've done this, the code works fine - when I have a set interval.
However, when I add randomness to the sprite's spawn times, collisions do not work all the time. Most collisions do not work at all.
I'm not sure what I'm doing wrong and would really appreciate any help in the right direction.
I think it has something to do with the schedule interval and how long it actually takes for the sprite to move across the screen.
Not sure though.
Also, if you could, I would also like to know the best way to remove enemySprite from the scene after it is off the screen?
Here's my code:
-(void)targetTimer {
[self schedule: #selector(enemySprite:) interval: 3.0f];
}
-(void)enemySprite:(id)sender {
CGSize winSize = [[CCDirector sharedDirector] winSize];
//SPAWN ENEYMY
enemySprite = [CCSprite spriteWithFile:#"eneymySprite.png"];
enemySprite.position = ccp (winSize.width/16, winSize.height/5);
[self addChild:enemySprite z:300];
CCAction *moveEnemyRight = [CCMoveTo actionWithDuration:3 position:ccp (winSize.width/1, winSize.height/5) ];
[enemySprite moveEnemyRight];
if ( enemySprite.position.y >= winSize.width ) {
//Best Way to Remove enemySprite from Scene?
}
NSLog(#"Collision");
[self unschedule:#selector(enemySprite:)];
unsigned int t = arc4random()%4 + 1;
[self schedule:#selector(enemySprite:) interval: t];
}
You have to craete an array of your enemies to be able to check if they leave game area (screen in your case). In your code this part
if ( enemySprite.position.y >= winSize.width ) {
//Best Way to Remove enemySprite from Scene?
}
will never be called. Because enemySprite.position.y >= winSize.width will be always NO as you just created this sprite and place it to the game area with coordinate
ccp(winSize.width/16, winSize.height/5)
I'm trying out new things for a simple game in Portrait mode, I want to add a seamless scrolling background to a game, the image is 512x512px.
The Main scrolling I want to have is Vertically, but I want to be able to scroll sideways too within the bounds of the image size. How should I go about with this, I'm using cocos2d.
David
Try repeating the texture (in this case within 2000px)
CGRect repeatRect = CGRectMake(0, 0, 2000, 2000);
CCSprite *background = [CCSprite spriteWithFile:#"Background.png" rect:repeatRect];
ccTexParams params =
{
GL_NEAREST,
GL_NEAREST_MIPMAP_LINEAR,
GL_REPEAT,
GL_REPEAT
};
[background.texture setTexParameters:¶ms];