How can I preset sprite positions in cocos2d - cocos2d-iphone

I am currently building a playing card game. As usual, the first few steps were to build an array of cards, shuffle them, and then Deal them to each player (there are 4). I want the cards to appear in front of each player in a "fan" setup, much like if you have 15 cards in your hand how you would spread them out equally. I am very new to COCOS2d and I'm having some trouble figuring out this component.
My question really is this- how can I code my cocos2d project so that the playing cards dealt go to pre-determined positions in front of each player? I want the cards to appear fan'd out in front of each player. Any suggestions?

For each card, create a CCNode object and add the card sprite as child of the node. Position the node where the bottom of the cards should align and rotate around.
Next, position the sprite to be offset vertically from its CCNode parent. In other words, set its position to (0, 100) for example. It should be more than half the card's height, perhaps two thirds. Then rotate the CCNode parent, this will rotate the card as well with the position of the CCNode being the center of rotation.
Repeat this for all cards in sequence and you can lay them out as a fan from left to right, or right to left depending on the order you add the node+sprite.

Related

Unreal 4 C++ Actor Movement

I have data for an actors movement which is being read in from a file at the start of the game. The data that gets read in contains Vector positions where the Actor should move to next. I currently have the Actor moving from Position to Position no problem... until I start to add animation to a Skeletal Mesh attached to the Actor.
My problem: How can I found out the velocity to work out which animation to play idle, walk, jog and running? It currently doesnt have a velocity as i am lerping the position:
SetActorLocation(FMath::Lerp(GetActorLocation(), newPos, 0.01));
Any thoughts on how to set the right animation based on distance travel and speed?
Should I move my Actors movement to Character so I can use AddMovementInput to get velocity. Then, If i go down that route, how to I say:
Move this character from my current position, to my next position in X amount of time giving the character the correct velocity to use in the animation selection.
Can you normalize the difference between the two vector lengths (GetWorldLocation) and use the abs(floating point) result as the X variable to put into 1D Blend Space to do idle, walk, jog, run in your Animation BP? Also be sure to account for an "acceptance radius" or else once it gets to location it won't quite get it and keep turning quickly.
Not sure why you're Lerping from Vector to Vector. I would've personally used (MoveToActor or MoveToLocation):
AMyPawn->MoveToActor(AMyActor, 90.f,true,true,false,0,true);
So much cleaner! Also MoveToLocation, using BT/BB.

C++ SFML - How to make bouncing sprite?

I try to make 2D game with C++ using SFML. I have drawn sprite and now I want to make that sprite moving automatically to random direction and when it hit wall then it bounce away and change direction. I don't know how to do auto moving sprite what bounce from wall... So please help me.
sf::Sprite has a member function setPosition (float x, float y) that you can use to set the position of the sprite before it's drawn. By moving the sprite to a new position each frame you create the impression of movement, much like a cartoon. By comparing the position of the sprite with the position of other elements in your scene, like the walls, you can calculate when 2 objects hit and take appropriate action. Typically it works like this:
Reset a clock at the beginning of a new frame, you can use sf::Clock or C++'s chrono for example.
Update the position of all elements in the scene that should be moving with something like: ObjectSpeed * Previous frame time
Draw the frame
Save time elapsed for calculating the next frame
Loop

Make 100 sprites from single sprite object

I am making game in cocos2D , in that i am using TMX map in that. Now in that , I put stars as score, player has to collect the stars , so that its score will increase.
My problem is i want to run repeat forever action on every sprite. I don't add that sprite to the tile map but i just make one extra layer and in that, i put tiles with star property.
Now, Where i add this tile map, at that time i check all tiles in the meta layer with star property and i want to put star image there.
My question is, As i don't know the number of tiles with the star property, so we can't make that much object array of CCSprite. And I know that we can't add one CCsprite object in scene twice.
How can i proceed to this problem?
Any kind of help will be appreciated..

Centring Sprite or moving camera? C++/Opengl

I'm self learning C++ and playing around 2D tile mapping.
I have been reading through this scrolling post here, which is based on this tiling tutorial.
Using the above tutorial and some help from the Pearson, Computer Graphics with OpenGL book I have written a small program that draws a 40x40 tiled world and a Sprite (also a tile).
In terms of drawing/render order, the map(or world) itself is that back layer and the Sprite is the forward most (or top) layer. I'm assuming that's a good way of doing it as its easier for 2 tiles to interact than a tile and a custom sprite or rectangle. Is that correct?
I have implemented a Keyhandling() function that lets you move the map inside the viewport using the keyboards arrow keys. I have a variable called offsetx, offsety that when a key is pressed increases or decreases. Depending on whether I assign the variable to the map or sprite, I can more one or the other in any direction on the screen.
Neither seems to work very well, so I assigned the variables to both (map and sprite) but with positive values for the sprite, and negative for the map. So upon a key press, this allows my Sprite to move in one direction whilst the map moves in the opposite direction.
My problem is, the sprite soon moves enough to leave the window and not enough to bring the more of the map into the scene. (The window only shows about 1/8th of the tiles at any one time).
I've been thinking all day, and I think an efficient/effective way to solve this issue would be to fix the sprite to the centre of the screen and when a key is pressed the map moves around... I'm unsure how to implement this though.
Would that be a good way? Or is it expected to move the viewport or camera too?
You don't want to move everything relative to the Sprite whenever your character moves. Consider a more complicated world where you also have other things on the map, eg other sprites. It's simplest to keep the map fixed, and move each sprite relative to the map, (if it's a movable sprite). It just doesn't make much sense to move everything in the world whenever your character moves around in the world.
If you want to render your world with your character always at the center, that's perfectly fine. The best thing to do is move the camera. This also allows you to zoom your camera in/out, rotate the camera, etc. with very little hassle in keeping track of all the objects in the world.
Be careful with your usage of the word "viewport". It means a very specific thing in OpenGL. (ie, look at the function glViewport). If your book uses it differently, that's fine. I'm just pointing this out because it's not 100% clear to me what you mean by it.

Parallax Scrolling With Finite Length

I have a side scrolling platformer that uses Chipmunk and Cocos2d for iPhone. The player moves from one side of the level to the other side of the level to complete the level. The player actually moves from one side to the other; the background is not repeated to create the illusion of scrolling.
However, I have been befuddled as to how I could do this with a parallax background. The level goes to about 3000 on the x coordinate.I cannot use an image that large. I also cannot make the image repeat itself after the player reaches a certain point because the player is not standing in one location.
Any suggestions?
You can split the background image into 3 images, each 1024 pixels in width. Simply offset the 2nd and 3rd image sprite's position by 1024 times 2 respectively times 3.