简体   繁体   中英

cannot move and rotate two CirclarShape objects together in SFML

I have defined a CircularShape named car having 3 points(displayed as triangle) and Circular shape field which is circular in shape, I want field to stay at tip of the car and move along with the tip of the car but the problem is when i run the program, they don't move together, some ambiguous behaviours is there I think there is some problem with position and origin of both the shapes please correct me, car's origin cant be changed though for some future purposes. Also can someone suggest me how can i ensure that my car+field doesn't move out of window boundary here is the code

http://codepad.org/CJ0JR6Qc

ofcourse it would not run in codepad.org i have posted link just for conveinience purpose

You are currently missing a game loop therefore all your movement will be very unpredictable as it depends of the processing speed of your computer.

To evaluate further, assume your car moves 10 pixels every time the code will be called. If your processor is fast and can run through your code 100 times a second, you car will be moved 100*10pixel = 1000 pixels per second. If your computer can only run the code 10 times a second, your car will be moved 10*10pixel = 100 pixels.

You should read into the principle of game loops. There are many questions already answered in the sfml forum and there is a tutorial about measuring time on their site (see http://www.sfml-dev.org/tutorials/2.4/system-time.php ).

To ensure that your shapes/entities/etc. don't move out of a specific region you should first update all positions in your game loop and then check if the new position are allowed. In your example you would check if the position of your shapes are smaller than 0 or greater than your window-size. This question was also already evaluated many times in the sfml-forum an you should find much better help with searching 'bounding boxes' in their forum.

hope this helps. best wishes,

Essi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM