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.

Author
Message
My games are free
16
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 6th Jan 2011 01:11
Can someone give me an example code of help how to:
For example - in 2d game, if player walks to front of a house and presses "enter" so he enters the house. so my point is how to change the scenery when player "enters" other house and gets back
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 6th Jan 2011 02:25
That's going to depend hugely on how you do your 2D game.

You could have all the scenery inside the house already set up and just remove the roof when the player goes through the door or you could have it remove what's onscreen and paste a fresh load of sprites to the screen.

How you do these again, depends hugely on how you're doing the 2D engine.

My games are free
16
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 7th Jan 2011 20:41 Edited at: 7th Jan 2011 20:41
ok i still did not get the image what kind of code should i write for that but yea something like that i was searching thanks still
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 7th Jan 2011 20:50 Edited at: 7th Jan 2011 21:03
Lol, why don't you get the code for a basic world sorted first before you start trying to enter buildings in it.

Just have a sprite offscreen somewhere:


and whenever you need a picture as part of your world do something like this in your main loop:

But replace IMG with whatever picture number you want, and use those 3 lines multiple times for all the different locations of images you want on the screen.

Here's an example if that's hard to understand:


And here's the media to go with it in case you can't be bothered making your own.


EDIT:
Here's a poor attempt at showing you how to do backgrounds and foregrounds using this system (I've slowed it down so you can actually see what it's doing before it randomly generates a new background/foreground):


My games are free
16
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 7th Jan 2011 23:41
oh okey thanks, i have never really understood sprites
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 7th Jan 2011 23:44
xD Probably best to learn before you try doing complicated things with them.

My games are free
16
Years of Service
User Offline
Joined: 28th Sep 2009
Location: Under your Bed
Posted: 7th Jan 2011 23:48
yeah you are right i should learn the sprite commands tomorrow

Login to post a reply

Server time is: 2026-07-19 03:40:56
Your offset time is: 2026-07-19 03:40:56