I want to be able to remove a tile from my game when my player touches it. The only way I have found is to hide the whole layer which is not what I want to do.
I have the collision detection working fine, I just need to be able to remove the tile on collision or when the player/sprite gets to that position.
Any ideas? Thanks.
You can remove tiles with:
[_layer removeTileAt:CGPointOfTile];
Related
I searched this on the internet but I still haven't found the answer I wanted.
So, I have a 2d tiled game and each tiles position is a multiple of 1.25 for example 7.5, 3.75. There is going to be a player walking on top it and i want to control the player by dragging it and if you release the touch it would be perfectly on a tile instead of in between the tiles. Right now, I can't even figure out how to drag the gameObject with touch. Can anyone help me and explain to me how to do that?
You need to have a collider on every object you plan to move. Then create a class whose sole purpose is to fire a Raycast. Detect when a touch happens. Then fire the Raycast.
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
You will notice that you have what you hit; with that you can send a message to that particular object.
hit.collider.SendMessage("move");
Inside the object that you hit, you now have to use the coordinates of the touch position to update the transform.position.
I'm bulding a simple application using SpriteKit for iOS 7 / 8 but I'm having some issues with my sprites when I try to touch and launch some events from one of two nodes that are too close to each other.
When I try to touch one of them, I end up touching the upper layer one square mask, and if I change the [self addChaild:] order it happens the same but with the other one.
I want to know if I can create a more precisse mask for my nodes so this won happen when I try to touch them. I know I can create a physics world and a physics body for each of them to control Collision Detection but I don't know if this is the right approach.
BTW... I'm using the methods touchesBegan:withEvent: and touchesEnded:withEvent: for touching events detection.
PD: if you need any more info about my implementation please let me know.
I want to write a simple top down racing game for iOS. I want to use Sprite Kit instead Cocos2D , I'm new to game development and I have a question:
How can I create the race tracks? What I think is: One single big background image for each track and a car that moves over it and remains inside the track by interaction with a path. The path is inserted by a coordinate system in the level code and represents the "borders" of the road.
Is this a good way to start a top down racing game? Or are there better ways? How can I "draw" the path over my background image?
You can use "Tiled Map Editor" http://www.mapeditor.org/ to create your maps. I'm thinking you'll only need a few unique tiles, one for straight track, one for grass, one for curved track, maybe some trees, etc.
As for the path, you can try to use an polygonal edge physics body? And then move the car to where the user touches on the screen. if the user tries to move the car outside, the car will bump against the physics body of the edge.
I have a large sprite. I want to animate parts of it. Obviously I don't want 30 images of said sprite, I want only the difference, that light blinking or something.
How do I handle that? So far using many images for sprite animations has been way to go for me.
A SKSpriteNode can have children, so you can overlay as many as you like on top of a given SKSpriteNode.
For example if you had a christmas tree, you could put 20 lights on the tree by just adding a child SKSpriteNode for each light and positioning it appropriately. You could then have each of those lights animate independently and dynamically.
You can create you sprite with something like layering.
In practice it will be looking like sprites (that will be animated separated) under 'big' sprite that you do not want to animate.
Im using Chipmunk with Cocos2d to make a gravity based puzzle game, however I have reached a part of my project whereby I need a sprite that once drawn does not move and cannot be moved by the other sprites within the environment.
In essence...
Can I create a static (non moving) sprite that is not affected by in game gravity or other objects in the game.
Thanks in advance I've only been doing this project a week....
Yes, this is possible.
1) Create a body with infinite mass and moment.
2) Do not add the body to the space.
3) Create the desired shape.
Use cpSpaceAddStaticShape to add the shape to the space.