CALayer obstacles? - cocoa

I am putting together a 2d RPG in Cocoa just for learning and for fun.
I've got the sprite moving around and animating just fine... but not sure how to approach making obstacles. Take for example Mt. Zozo here. I don't want Setzer falling off a cliff, or climbing up on those dangerous looking rocks!
I was thinking that I might have to draw in some layers where I don't want him to move and put some code in my move keydown methods that test that the resulting position doesn't contain a point that is also contained by an 'obstacle' layer. But that seems really not generic and a lot of work.
Any thoughts?
Thanks!

In the end, pretty simple.
Remember that I am using a 32x32 px grid for sprite movement.
Just put down layers wherever you don't want the character to move, and then when adding possible the movement tiles, test if the position of the movement tile is the same as the obstacle.
if (upOne.position.x == obstacle.position.x && upOne.position.y == obstacle.position.y)
upOne.hidden = YES;
I tried using contains point but that was problematic. Anyways, this worked :)

Related

scratch bounce then upside down

Above you can see my Scratch workspace where the ship on the left is upside down when it is running, and IT IS THE SAME CODE.
Is it a bug of scratch or some kind of other problem?
Make sure that the sprite is set to don't rotate in the info tab
Alternatively, you can add the set rotation style to (don't rotate).
It will make the sprite no longer rotate all around.
Otherwise, if you want to make it look like it is walking rather than just looking in a direction while walking, replace the parameter don't rotate to left-right
I use Scratch 2 for kids programming classes and as a beginner at this object, at first I had the same problem that confused me a lot as to what would provoke the Sprite to turn around.
It turned out that Scratch makes the character rotate when it bounces off the edge (I guess that the reason is not functional).
Anyway to solve it I added the move->set rotation style (don't rotate) before (the position doesn't matter, could as well place it after) the if on edge bounce block.

Libgdx | Set black color to everything outside of circle

How can I set a black color to the whole screen, excluding a shaperenderer circle? The circle is basically my game world, anything that leaves it shouldn't be visible. Is there some way to create a reverse circle pixmap (eg..A circle, but inverted) to overlay everything except for the circle game area? Or maybe a way to clear the screen, excluding parts? Thanks!
You could try the approach you mentioned in the comments. Using a black image with a circular hole in it. Then have each assigned to a different camera much in the same way you would set up a HUD in libgdx.
You might want to take a look at shaders, this approach is really flexible and lets you even control how rapid the transition is. Just the basics of GLSL should be sufficient.
https://www.youtube.com/watch?v=caQZKeAYgD8 Here's a decent tutorial.

Unity -- 2d platformer sprite animation in different position

I'm trying to make a simple 2D platformer game. So I got the walking and idle animations working for my sprite, but for some reason when it transitions to the run animation, the sprite is a little off the ground? Does anyone know how I could fix this?
The sprite looks like this in the two animations:
idle:
run:
There's a number of things this could be. Here's some things to consider.
Ensure that the location of the sprite hasn't changed. Do this by looking in the inspector.
Look at the anchor point for each sprite, and make sure they are at the same point.
Check for size differences.
Make sure the sprite is cropped correctly
Look at the animation state diagram to see if an unusual state change occurred.
I'm sure I could find more possible causes, but the bottom line is, take a look at everything you can think of that might be causing the issue. If you've tried that, then look around and see what else you can see. Finally, if that doesn't work, try asking here with everything you've tried included.
I had this problem too and just fixed it. it's actually simple. What causes this is the pivot of your Sprites. You have to go back to the sprite editor and set the privot of your sprites to the same value and that's it.

Using "broken" option in animation curves doesn't work for rotation

I'm making a game using sprite sheets, but I was curious to see if I could animate other sprites into the animation. Indeed, it is possible, however the animation's curve has to be dealt with, or else you have one part choppy, and the other very smooth. I found this resource which helped: http://answers.unity3d.com/questions/893479/how-to-make-not-smooth-multi-sprite-animation.html
While the "broken" curve works for translation, it seems to be without effect on rotation.
This is what happens instead:
As you can see the curves are straight, but the animation does not reflect that.
I'm wondering if this is a bug?
I haven't found any other resources mentioning it. I realize I can simply create another sprite sheet, but it'd be efficient if I could do it in this manner, I believe.
Try setting different interpolation modes from context menu of rotation property. Eeuler angles( Quaternion Approximation ) should be suitable for you

How do I animate clouds?

I have 3 nice and puffy clouds I made in Photoshop, all the same size, now I would like to animate them so they appear like they were moving in the background. I want this animation to be the base background in all my scenes (menu,settings, score, game).
I'm using cocos2d, I have setup the menus and the buttons so the work but how do I accomplish this?
I was thinking to add this as a layer, any other suggestions?
Can anyone show me how some code how to make this please?
David H
A simple way to do it is with sine and cosine. Have slighly different parameters (period and amplitude) to ensure that the user doesn't realise (as easily) that they are programmatically animated.
You may also want to play with animating the opacity value. I'm not sure if layers have those, otherwise you'll have to add the clouds to separate nodes or images and applying it to them.
It's hard to be more specific without knowing what the images look like.
The simplest way to animate anything is to add the sprite to the scene, set the position and call something like...
[myClouds runAction:[CCMoveBy actionWithDuration:10 position:CGPointMake(200, 0)]];
This will slide the sprite 200px to the right over 10 seconds. As Srekel suggested, you can play around with some trig functions to get a more natural feel and motion paths, but you'll have to schedule a selector and iteratively reposition the elements.
The more difficult part of your questions is about getting the animation in the background of all scenes. Keep in mind that when you switch scenes, you're unloading one node hierarchy and loading a new one. The background cannot be shared. You CAN, however, duplicate the sprites and animation in all scenes, but when you transition between them there will be a jump.

Resources