How to draw multiple circle shape in SFML - sfml

i really want to know how to create a multiple circle shapes in SFML.
I know we can create the circle shape with sf::CircleShape
I want to create a circle shape with the same radius everytime i click on my screen and i have no idea how to do that, please help me.

You need to use an event loop to capture mouse events and any other event for that matter. See https://www.sfml-dev.org/tutorials/2.0/window-events.php for details.
Read the documentation or search via Google for more.

Related

How to set up a score board using SFML and Box2D in C++

I want to set up a scoreboard for these two players (Pikachu)
My questions are:
how to detect when the ball touches the ground?
how to setup an object that can change during the game?
like the two in this picture:
I'm very new to SFML and Box2D, so even if I try to read the source code to see what I can use to implement things above, I still have no idea.
Can anyone give me some clues?
To create a scoreboard similar to the one in the image provided you can put text on the screen that holds the current score of the players and then placing it in the position where you want the score to be placed on the screen. In SFML this would be done by creating a sf::Text object.
To answer your other questions.
1.how to detect when the ball touches the ground
A simple way of doing this would be to check the Y value of the coordinates of the ball and from that determining if the ball is touching the ground.
2.how to setup an object that it can change during the game.
I am unsure what you mean by this.

Displaying a rectangle with a border using Cosos2d Js

I am new to Cocos 2d js.....
I want to know how can I draw a rectangle having a border to it using cocos2d js??..
I tried to google but didn't find any sample code or something similar..
which is quite simple to do using HTML and CSS...
Thanks.
Yo need to add a draw node to your scene/layer and draw a rectangle on it. For example, say you have the following method within your layer:
{
...
var dn = new cc.DrawNode();
this.addChild(dn);
dn.drawRect(cc.p(50,50), cc.p(200,300), cc.color(255,0,0,255), 3, cc.color(0,255,0,255));
...
}
The function call parameters are: drawRect(origin, destination, fillColor, lineWidth, lineColor).
This is from the samples found in the samples/js-tests folder that should be in your cocos2d-js folder. For more information, check out the API on the drawing nodes here: http://www.cocos2d-x.org/reference/html5-js/V3.3/symbols/cc.DrawNode.html
PS: if you want to draw a filled circle with a line color, however, note that there's not a function for that currently. There are a few workarounds, the best one I've found is to use a drawDot for the "inner solid part" of the circle, and a drawCircle for the outer part.

SDL drawing a sprite once a button is pressed

So, i'm a complete stranger to SDL and i found this nice code online:
http://gamedevgeek.com/tutorials/animating-sprites-with-sdl/
I was just wondering how to make it so that when i press space a shape gets placed infront of me? For instance, im just walking around and when i press space a rectangle or another bmp is places in front of me.
Sorry for not being explicit in what i want, i just dont know how to explain it.
You need:
Another Surface to draw (blit), made from the rectangle.bmp. This would use the same method as is used for the grass (or the player if you wanted animation).
Knowledge of where "in front" is: up, down, left or right. Look at the code and see what variables change when you press one of the arrow keys. (Hint: don't use rcSprite.) In a larger game, you would want to define a new variable for the direction that the player is facing, and then use that for both the sprite animation and for placing the rectangle, as it would make the code easier to understand.
Some new code in HandleEvent, which does something if the key is SDLK_SPACE.
Then calculate a position to place the rectangle (say, the player's position with 50 added to "x" if they were facing right), and draw the rectangle in the same way as the grass.
In general, look at what code has already been written, and Google for stuff you don't know (e.g. the name of SDLK_SPACE).
Good luck

Particles around a sprite

I'm new to the CoCos2D development. I have checked out some tutorials and went on trying to develop a little idea.
I have checked some partical tutorials and it all looks nice but I still have some questions about it. I have seen how to call a particle and let it follow wherever you click on the layer and so on but I need something more.
Let's say I have several circle shaped sprites on my Layer. Is it possible to do the following: click on a sprite and then a partical trail should go around the sprite so you as a player can see it is selected. The particale should keep circling around the sprite until I select another circle shaped sprite which result in dissappearing of the previous particle trail and appearing onto the new selected sprite.
Is this possible with the particle system or should I look for another way of doing this ? Any type of help is appreciated.
kind regards

Scrolling Background with Cocos2D and Box2D

I am trying to create a simple game that mainly consists of a ball rolling down an incline. The player's only control is to cause the ball to jump. My question is, what is the best way to make it appear to roll while generally keeping the ball at the same place on the screen? I have considered CCCamera, but it seems like it's not the best option since I want a repeating background image. Scrolling the background manually is also giving me trouble because it's not clear how to get the ball to stay in one place while letting Box2D handle the physics. I'd appreciate any help as I've been stuck on this for quite a while.
Use CCFollow on the layer where you draw the game stuff, and let it follow the ball sprite:
[gameLayer runAction:[CCFollow actionWithTarget:ball]];