I have a sprite using spriteWithFile.
I have collision detection on this sprite which currently only detects on the middle of the image. The middle of the image is currently detecting collision, so half half the image will be over the collision point when the detection is made.
How do I change this detection point on the character sprite?
Thanks
What about using some physics engine? Box2D for example. It's coming with cocos2d, it's fast, it's easy to use.
Related
I'm working on a c++ system that tracks a drone via opencv motion detection. The problem occurs when there is a lot of untracked motion in camera sight. The system sometimes sees other motion and then thinks this is the drone that I'm trying to locate. The problem is that the drone then starts doing things it should not. So I'm trying to figure out if I can reduce the tracking field that my system won't make illogical decisions
EDITED: Is there a way to track the drone depending on a ROI around the position the drones was located in the last frame. So that my program only checks in a ROI where the drone could fly to within the time frame of 1 frame. So the tracker can not locate the drone at the other side of the camera view.
I’ve tried my best searching online and reading the documentation to find a good answer, but I have yet to find one.
I’m creating a multi-platform 2d side-scrolling retro game in Cocos2d-x v3. The engine is rather new to me, but I do have decent experience in C++, Xcode and game development.
The game which I’m trying to create is utilising super minimal pixel art and I’m at a loss as to decide which approach would be best. Currently I have two ideas:
Work with a fixed resolution (e.a. 240x120, I’m working with
really(!) small sprites) and use Design Resolution to scale the entire canvas
upwards to the screen size using kResolutionNoBorder.
Pros: I don’t have to scale my sprites and I can just use a short piece of code in the Init() function.
Cons: Not sure if you can use Design Resolution to scale pixel perfect?
Scale every sprite so that it appears to be running on a ±240x120
resolution.
Pros: ?
Cons: I have to scale every sprite which means more code and less clarity as to what is really happening on my canvas.
I read the multi-resolution-support page on the Cocos2d-x wiki, but it didn’t really give me advice on what would be the best approach for retro games.
I feel that I don’t have enough knowledge about Cocos2d-x to make the right decision yet, and a voice in my head says I’m forgetting something important.
There are more factors at play. How do want the game to look that are diffrent from 240*120.
I'll suggest scaling the screen for pixel art games. You can also control aliasing/anti aliasing param for all texture. Generally for pixel game, anti aliasing is turned off.
KResolutionNoBorder might crop your game edges to fit it in. There are other options,like kResolutuonFixedHeight, kResoltuionFitAll, depending to game requirement and HUD placement.
Well, it still can look pixel perfect in large screen, cocos2dx uses float for the size and position, so even if 1 pixel in your design view is represented as 5x5 pixels on the screen, when you move the position 0.2 point it will look like it moves 1 pixel. How precise it can be depends on the device screen resolution.
I would go for scaling the canvas
I'm working on a game and I need to detect collisions between a line and a polygon. After much googling, it seems that cocos2d does not support polygon collisions?
I'm able to perform line and rect collision detection, but not polygon.
Do I have to move to Box2d? Any advice is much appreciated.
Cocos2D doesn't offer any kind of collision detection. What you want is a ray vs polygon intersection test, that's something you can do with Box2D or Chipmunk. Both are included in Cocos2D (for iPhone). Box2D and Chipmunk allow for implementation of the game physics like gravity, wind, collision detection etc.
If you require to do a 'sort of' detection in plain Cocos2D then I recommend the use of CGRectContainsCGRect or CGRectContainsCGPoint or CGRectIntersectsCGRrect functions to do the same. This may help you achieve what you want but it won't be as nice as the use of Box2D or Chipmunk game physics.
cocos2d offers just simple collision detection like CCRect::rectContainsPoint(in cocos2d-x) or rectIntersectsRect.
If your polygon is a rectangle then you could make the detection by judging if there is a point of the line contained by that rectangle.
I'm building a 2d game engine using c++ and opengl. Now i have implemented a scene graph and now every node of this graph is being rendered every frame. What are good algorithms for clipping nodes that are outside the viewport?
at a most simple level, you could use quadtrees for culling, it has the added bonus of being useful for collision detection as well, Wikipedia has a page explaining it.
I'm planning to build a basic rebound iOS game in Cocos2D. Will Box2D be best suited for the following scenario?
The layout will consist of a target at the top of the screen, with obsticles in the middle of the screen, blocking direct view of the target from the bottom. The user will shoot a ball from the bottom of the screen by rebounding it of the sides and around the obsticles, aspiring to hit the target. Similar to a breakout style of game.
As the game levels progress, the obsticles will be moving dynamically, left to right and back, up and down etc..
I understand that the collision detection can be achieved using Cocos2D alone. Can the rebounding and trajectory of the ball off obsticles and walls also be achieved without using a physics engine?
I will have no need for gravity in the game scenario. A reduction in the velocity/speed of the ball will be essential.
Please note, I am new to iOS dev, coming from a background in front-end web dev.
Advise and help much appreciated.
Thanks
You certainly can do all that without using an existing physics engine. Once you start doing collisions with moving objects and objects of different shapes, though, it starts to become advantageous to use an out of the box solution.
It's easy to setup box2d without gravity and it will give you all of the collision calculations and velocity stuff