In cocos2D,if you give a CCSprite a position,it actually means the position of the anchor of the CCSprite which is usually different from this sprite's local node space origin(the bottom-left of the texture),Right? But when I make a body with a custom polygon from a texture in Box2D and give the body a position,I found that it means the position of local node space origin(0,0) of this body which seems the the bottom-left of the texture where I get my polygon from.I am wondering if there is not an anchor in Box2D body like in cocos2D sprite?Does the position of body mean the position body's local coordinate origin?If I get the body's shape from a texture(picture),does it mean that the body's local coordinate origin is the the bottom-left of the texture? I hope that I express my confusion clearly....
Confused with the anchor and local node space origin of the body in Box2D
245 views Asked by user3050371 At
1
There are 1 answers
Related Questions in COCOS2D-IPHONE
- How to get C char * string value in swift?
- Cocos2dx Crash - Version 3.17.2
- How can i change the entire speed (timing) of a android game made with cocos2dx?
- Adding code to my AppDelegate / AppController
- Migrate Cocos2d to latest device support
- Cocos 2dx control playback speed of currently playing audio effect
- I am having a problem building my app locally on my Mac
- quick cocos xcode with Undefined symbols for architeture error
- can not change scenes in Cocos2d
- Lexical or preprocessor Issue: Exporting Cocos2D as a iOS framework
- cocos2d, can we call a function in "sequence" on a sprite?
- Cocos2d-x v4.0 crashing in iPhone Simulator with Xcode 12, Xcode 12.1, Xcode 12.2
- How to create vibration with customized duration on ios's objectiveC?
- Using python to simulate 2D elastic collisions
- Black screen on app launch AFTER using storyboard launch only on iPhone 11 onwards
Related Questions in ANCHOR
- I want to show another second tag on the click of first anchor tag and hide the first anchor tag
- How do I make my website Header clickable so it redirects me to the home page?
- Displaying and hiding links based on access permissions
- JavaScript anchor file download - override file name from Content-Disposition header
- Angular 17 standalone link for the other section of the page on the same page
- The anchor menu inside the scroll block does not work correctly
- JavaScript - Get fragment value after Scroll To Text Hash Fragment '#:~:text=' from a URL
- Javascript that displays different page every hour needs to open in new window
- Anchor Link scroll not working correctly when Javascript component included in page
- Error: IDL doesnt exist. | Rust | Solana | Anchor
- Clicking anchor links rendering incorrect scrollTop value (all browsers)
- When I run "anchor test", I am getting this error (for a sample Solana program"
- How to troubleshoot third-party cookie restrictions?
- Elementor anchor links to another page disables smooth scroll on homepage
- How to test Metaplex instructions with Anchor on localnet?
Related Questions in BOX2D
- Can't resolve undefined reference to box2D C++
- Box2D not simulating
- How to create a non-standard shape in a box2d python. Namely, a figure in the shape like Г, T, Z, like in Tetris?
- Is it possible to implement interaction pybox2d and pygame
- sync of body and sprites for animation?
- How to know which side of a ChainShape is being collided with?
- Why is this object not recognized?
- Box2d body's velocity slows down without any force applied
- Why does my installation of box2d fail even though I already have swig installed
- Box2d body, preservation of b2BodyDef, b2Shape, and b2FixtureDef
- error while installing pip install gymnasium[box2d]
- Ground Box doesn't work in LibGdx and Box2D with Scene2d
- LibGDX Displaying UI elements in game world
- LibGDX camera.project() is not working properly
- My LibGDX game project is rendering only the background image
Related Questions in COORDINATE
- Astropy: determe if a point (RA, DEC) is inside a squared region given the coordinates of the corners of this region
- Get Coordinate Latitude Longitude from The Grey Point Google Map
- Constant Radius Turn From Tanget Vector and Two Points
- Extract list of values from array given coordinate list
- How to transform earth-centered to topocentric-horizon in c#?
- Swift: Coordinates not accurate when using latitude/longitude
- Converting coordinate ASC file (raster data) into a XY coordinate data frame
- How to find black dots coordinates (X,Y) in an image
- Javascript replace coordinate [1.111111,2.22222]
- Drawing boxes on basemap with real Lat-Lon
- Leaflet how to convert a L.CRS.SIMPLE coordinate to a normal L.CRS.Earth one
- extract netcdf pr based on one location for a given lat and long
- Replace xarray coordinates with another coordinate
- Calculating the intersection coordinates given by 2coordinates and the radius
- What would be best solution for adding different sized objects to world?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
When you create a Box2D body, you give it an initial position. This is NOT the center of mass, but the position of the "container" for all the fixtures attached to that body. All the fixtures are attached relative to that point.
For example, in the body defined in this function, I am attaching several polygons (squares) to the body. The overall effect is to create a giant letter "T".
Note that the vertices for each polygon are relative to the body position, which is (0,0).
A sprite is displayed relative to its position by its anchor. The relative position is expressed in the range [0,1] in both (x,y) coordinates. Unless there is pretty good reason to do otherwise (for effects), I usually set the anchor to (0.5, 0.5) so that sprite's x,y display center shows up in the same position as the sprite pixel position. See this post for more details on this.
So to create sprites for all those fixtures:
void MainScene::CreateSprites() { Viewport& vp = Viewport::Instance(); float32 ptmRatio = vp.GetPTMRatio();
for(int idx = 0; idx < _fixturePositions.size(); idx++) { CCSprite* sprite = CCSprite::create("arrow.png"); // The default sprite anchor is (0.5,0.5). This // is being done to drive home the point. sprite->setAnchorPoint(ccp(0.5,0.5)); AdjustNodeScale(sprite, 1.0, ptmRatio); _fixtureSprites.push_back(sprite); addChild(sprite); } }
You will notice the use of the viewport. That maps the position in the Box2D "meter" space to the pixel space of the screen. You can see a post with more info on that here or by looking at other posts I have done on SO for Box2d (this topic is a common one). You need to scale the sprite size by the physical dimension you want it to be (meters) and the pixel to meter ratio (PTM Ratio):
If you just have a single sprite, you can make its position coincident with the position of the center of the body and lay it on top. If you have multiple sprites, you have to place and rotate each one:
And the result looks like this:
You can find the code for this entire project on github.
Was this helpful?