Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Tier 1 - Physics Shapes

Author
Message
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 28th Jul 2012 13:49
Morning all. The following piece of code has 2 problems but I'm damned if I can work out why. The code sets up 2 static sprites with physics. The sprite on the left is just a standard box 96 pixels by 96 pixels. The sprite on the right; I've tried to define a small box on the right hand side of the sprite 96 pixels high and 18 pixels wide.

Problem 1 is that neither of the sprites display - well I should say they appear then disappear very quickly. If I create the first sprite by loading an image, then both sprites appear correctly (but problem 2 still exists).

Problem 2 is that the sprite on the right's physics shape isn't where I expect it to be, it's to the left and up of where I thought I'd told it to be.



Can anyone tell me what I'm doing wrong?

"Happiness is contrary to the human condition" --White (to Black)
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Jul 2012 14:28
Not sure why the sprites are disappearing and not at my pc to test the code right now but the second problem is most likely just that the position of the second box is based on the top left of the sprite, not its offset.


this.mess = abs(sin(times#))
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th Jul 2012 14:45
Turning off 'SetPhysicsDebugOn()' will allow you to see your sprites... As for the second problem, as Baxslash said, its positioning it by its top left corner. From what I can see, you are trying to set the offset to the center of the sprite, right? If so, by default the SetSpritePositionByOffset is its center so there is no need for you to manually set the offset in this instance... I'm not 100% sure what you are trying to achieve, but here are the changes I'd make...



Not sure if any of that helps...
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 28th Jul 2012 19:05
If you do the SetSpriteShapeBox(2,0,0,20,48,0) and put Print("hello") in the do loop, it works fine.

I think the fact that you aren't doing anything in the loop is what is causing it to not really display the boxes.

I added 'if getpointerpressed() = 1 then print("hello")' to the loop and every time I clicked on the display, the boxes became visible.

I expect that the engine expects you do something in the loop and if it gets no instructions, it doesn't do anything to update the display (effectively clearing things).

Cheers,
Ancient Lady
AGK Community Tester
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 28th Jul 2012 19:29
Quote: "I think the fact that you aren't doing anything in the loop is what is causing it to not really display the boxes"


Thats interesting, and you're right! I wondered why some of my 'test projects' didn't show the images, yet other projects did. I just put it down to 'SetPhysicsDebugOn()'! Thanks for that!
Grook
AGK Backer
11
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 29th Jul 2012 22:27 Edited at: 29th Jul 2012 22:48
Thanks to everyone for their responses. @Funnell7, I didn't realise that regarding SetSpritePositionByOffset, always good to learn!

It's a bit odd though that the co-ordinates for SetSpriteShapeBox are relative to to the top left, but those for SetSpriteShape Polygon are from the centre (offset). I'm sure the help for these commands suggests both should be from the offset...

"Happiness is contrary to the human condition" --White (to Black)

Login to post a reply

Server time is: 2024-05-06 12:06:39
Your offset time is: 2024-05-06 12:06:39