(Follow-up question) How to make a 2D camera that follows a sprite? [for XNA-game] - xna

I was looking for tutorials on the net for a 2d camera that follows a sprite and I found a reply from this site:
(XNA 2D Camera Engine That Follows Sprite)
I made a simple game where in the sprite is loaded at the center of the game screen and it moves according to the direction I press from my directional key pad.
I tried implementing this code and added the Spritebatch instruction to my game. There seem to be no syntax error, but once I run the game, I only see the blue screen. Also, the sprite I used didn't appear.
(I'd like to imitate the player control of Tasty Planet where in the goo is controlled by the mouse and the screen follows it around. - trailer of the game: http://www.youtube.com/watch?v=az4VgetA_n0

Game development is sometimes best accomplished step by step. Especially when one is first learning :-)
What you want to do is first get some basics onto the screen 1) the player's avatar, and b) some static component like a wall, or floor.
With those in place and rendering on the screen, then you implement your camera component. This will be a class that takes the player's position in the world and offsets any "world" item by that much.
For example, if the player is at 10,10 in the world, and there is a tree at 5,5 ... the tree should be drawn at -5,-5, and the player drawn at 0,0 (assuming your coordinate grid's 0,0 is in the middle of the screen). And as the player's position moves, just subtract that from static world object that you draw.

Related

ARKit: How to detect only Horizontal floor excluding obstacles

I am developing horizontal plane detection application using ARKit. It seems to be working fine. Once floor is detected I am trying to place SCNPlane 2meter Hight and 2meter width horizontally from the centre point(detected floor). It is also working fine when floor is empty. If floor has some objects(obstacles like furniture) then SCNPlane is being placed over the object instead of the floor(under the object). How to detect only Horizontal floor excluding the objects. please guide me. thanks
When you are searching and have found the floor the ARKit will put out a grid, normally people use some kind of grid image to display this, but some don't want to show it. Once the grid has placed you place a SCNPlane, which i assume has an physical body as you say it falls towards the floor / furniture?
You can do this in 3 ways:
You can to stop the worldTrackingConfiguration once the floor has
been found.
You can once the floor has been found, fetch that Y-position and bind every object to fall towards that Y-position.
I guess you could check if the Y-position of the new detection overlaps with the floor detection, then it's fine else it's not. (I have not tested this one)

SpriteKit Racing top down Game

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.

Moving around the planet in sprite kit

I'm currently making a game where driving a moon lander across the terrain of alien planets. The lander is free moving so you can turn any direction you like.
I've got a camera centred on the player's vehicle and navigation is working well, however...
As the player approaches the horisontal sides (x) of the map I'd like the map to display continuously.
I've used a couple of different approaches so far; I've added an identical sprite as the map to the left of the map and created a method that moves the extended map to the right side if you approach that side instead, and I've also tested with two different extended maps, one for left and one for right. I've then setup physics for the extended maps and changed the landers position from one side of the map to the other as it collides with the extended maps.
My issue is that I'd like to have my enemies spawning and walking around the main map and as you approach the side you will of course not see the enemies on the other side of the map - you'd only see the extended map with no contents.
My preference would be for the world to "bend" so that as you approach the left edge you'd automatically see the right edge and vice versa. I have no idea whether this is even feasible so any suggestions are much appreciated.
Thanks in advance.
I'm not sure I understand your question. Maybe this will further discussion, anyhow.
If you are looking for a scrolling behavior then I would have two backgrounds (or more if you want a wider scrolling field) and your method for swapping the tiles around to make the background feel continuous, use the "camera" tracking technique and shown in Apple's sprite kit demo to follow your player (which it sounds like you are doing). Then when aliens move offscreen in either direction relocate them in the same way that you would swap out your background tile(s) with something like position.x += widthOfBackgroundTile.

Lime for Corona SDK - Camera focus on layer

Is there any solution for setting up focus on layer in Lime framework.
I would like to use this on game called "keepie uppie" with scrolling background (camera).
When you hit the ball the entire frame together with a ball and tennis racket moves up.
The figure below shows how I would like to make it work:
Check out the Camera from Lime. It basically creates a display group and moves everything relative to that. You can focus the camera on one of your game objects. The github repo includes an example of doing just that.
https://github.com/GrahamRanson/Camera

How to place sprites at specific x,y coordinates in xna 4.0

Okay im working on making a tic tac toe game for one of my game development courses using XNA 4.0 I need to place sprites or some other objects so the game can check if the mouse is being clicked in the correct spots. I am going to use transparent sprites as a kind of button. How do I code them to go to these specific x,y coordinates. The game board is drawn on the background, I have all the coordinates to where to place these sprites. I am just stuck on putting the sprites in the correct positions.
SpriteBatch.Draw has a position parameter. Pass in an appropriately-valued Vector2.
Well if you check the Draw method you will find a parameter for the position.
Check this code sample
spriteBatch.Begin();
Vector2 pos = new Vector2(10, 10);
spriteBatch.Draw(SpriteTexture, pos, Color.White);
spriteBatch.End();
This is how you draw a sprite, with SpriteTexture as the image, on the position x10, y10 with the color White to modulate the texture.
You can also find more informations here.
Keep in mind that there are many overloaded methods to the Draw method. One you can even pass in rotation information and the like. So .Draw(...) has a lot of functionality you can use beyond just placing a sprite.

Resources