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 / Making tilemap non moveable but still collides.

Author
Message
Mmarzex
11
Years of Service
User Offline
Joined: 26th Feb 2013
Location:
Posted: 7th Mar 2013 07:45
Hi all,

So I am currently drawing my tilemap in from a file where it draws every 16 pixels as a seperate 16x16 tile and loading it on to the screen. My question is how do I make them not move when hit or moved on by a sprite?

Thanks,
~ Mmarzex
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Mar 2013 10:24
?
SetSpritePhysicsIsSensor(
erebusman
13
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 7th Mar 2013 16:10
@Mmarzex : assuming your sprites are say 'the ground the player walks on' then you would actually not make them physics sprites at all.

Just set their depth below the player. You may want to use FixSpriteToscreen so they don't move.

Only if it is a physics sprites will the static command work.

You only need physics for sprites the player will collide with such as walls, boulders, monsters, etc.

If you want the physics system to detect a collision for picking up something like a coin or health powerup; then the SetSpritePhysicsIsSensor that Markus recommends is good for that use.

So essentially ; decide which sprites need to be physics and what type of physics.

The rest - don't need to be! Hopefully that is what you were looking for?

Mmarzex
11
Years of Service
User Offline
Joined: 26th Feb 2013
Location:
Posted: 7th Mar 2013 17:27
I need The background to move with the player. I'm doing a platformer. Would the best approach be to fix the tilemap to the screen and then unset it as it moves past a certain point?
Mmarzex
11
Years of Service
User Offline
Joined: 26th Feb 2013
Location:
Posted: 7th Mar 2013 17:37
Also I want to be able to have the player stand on the tilemap. Fixing it to the screen does not work for that.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Mar 2013 18:19
Perhaps a screen shot would help, so we can see what your tiles look like. If your map is not that large you can just scroll the screen using setviewoffset(). Or if it is a large map then you would have to redraw the tiles every 16 pixels, so you only have to display the on screen tiles.

Mmarzex
11
Years of Service
User Offline
Joined: 26th Feb 2013
Location:
Posted: 7th Mar 2013 18:35
The scrolling isn't my issue right now. What I don't understand is how I'm suppose to make it that the tiles don't move but that my player sprite effectively walks on them and doesn't just fall through. I already plan to use setviewoffset() as that will make it a bit easier for the size of the map I'm using.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 7th Mar 2013 19:09
Just set the ground sprites as 'Static'.

SetSpritePhysicsOn( iSpriteIndex, mode)

mode - The physics mode to use for this sprite, 1=static, 2=dynamic, 3=kinematic

Your character will them be able to walk across them, without them moving...
Mmarzex
11
Years of Service
User Offline
Joined: 26th Feb 2013
Location:
Posted: 7th Mar 2013 22:54
Alright setting it to static worked now though I have an issue with my tiles being drawn. It Keeps giving me this when I run the game:



Now here is what I drew it up as



Now my code is this for my Level.cpp where the functions for drawing are


I'm not sure why that is happening.
Jimmanator
14
Years of Service
User Offline
Joined: 12th Nov 2010
Location:
Posted: 10th Mar 2013 22:21 Edited at: 10th Mar 2013 22:23
If you are meaning that the top row is offset from the other rows you need to change
This :


To this:

Login to post a reply

Server time is: 2024-11-24 09:55:42
Your offset time is: 2024-11-24 09:55:42