Using projectx() & y() to put name above head?

Blitz3D Forums/Blitz3D Beginners Area/Using projectx() & y() to put name above head?

Guy Fawkes(Posted 2011) [#1]
Hi all. How can you use ProjectedX() & ProjectedY() to put a sprite with a named entity (Using nameentity), above a player or object's head?

Thanks! :)


Yasha(Posted 2011) [#2]
You wouldn't.

ProjectedX and ProjectedY return 2D screen coordinates for you to use with 2D drawing commands. A sprite however is a 3D entity: you position it in 3D space, not 2D screen space. The fact it looks 2D is inconsequential.

If you want to use a sprite, just put it above the entity's head. You may wish to raise or lower it, and scale it, according to distance from the camera (to make it seem the same 2D distance from the object and not to change size); but it's a fundamentally 3D object so you don't need CameraProject at all for this.

If you aren't using Blitz sprites (they're not great), and you meant "sprite" in the generic sense of "some 2D drawing thing" such as an image or single-surface quad, then you use CameraProject by supplying the camera, and X, Y, Z coordinates that you want translated to 2D screen space, and extract the X and Y values of the result with the ProjectedX and ProjectedY functions. You can then draw your 2D object over this point on the 2D screen (this part is all covered in the manual).


Guy Fawkes(Posted 2011) [#3]
Can you show me an example of drawing a named entity's name on a sprite above head? :)

Thank you! :)


Yasha(Posted 2011) [#4]
...OK. One sprite, one 2D projection.



This text doesn't scale with distance, because I couldn't be bothered to actually apply brainpower, I'm afraid (much like the way I will probably be far too lazy to answer any questions about this code). What other effects one would add depend heavily on what you would want the technique to achieve.


Guy Fawkes(Posted 2011) [#5]
This is PERFECT! Thank you! =D


Guy Fawkes(Posted 2011) [#6]
Except I made one SMALL thing that needs fixed. I added word wrap, I simply need it after it reaches the max width of the sprite's width, then it increases the Y scale of the sprite and continues word wrapping til it reaches the end of the string.



Thank You! :)

Last edited 2011


Guy Fawkes(Posted 2011) [#7]
Anyone?


Yasha(Posted 2011) [#8]
There are two reasons I (for one, obviously I don't have a patent on answers in this thread) didn't answer:

1) The new question is completely unrelated to the topic of the thread (this is actually important; someone who knows how to solve your new problem may not read to the bottom if the original one doesn't interest them; and it doesn't help other people reading archived conversations).

2) It's not one more small thing, it's quite a bigger deal than the original request.

I suggest you make a new thread about word-wrapping and see what comes of it.

And I recognise that you're really trying to be different from before, but wrapping a huge, new topic in "one more thing" is a sure turn-off for those who are already skeptical about how much work you're willing to do for yourself... so please don't do it in future.

Last edited 2011


Guy Fawkes(Posted 2011) [#9]
Anyone ELSE? :)


Rob the Great(Posted 2011) [#10]
Rez,

I notice that you're posting a lot in these forums. While I admire your intensity, I can't help but wonder if such a wide variety of programming topics is a good thing?

In order words, if I was trying to learn word wrapping, bezier waypoints, data storage and manipulation, physics engines, "recording" systems, random position generation while excluding certain areas, 3D Text Systems, timers, entity and line picking, special effects like splashing water, and even SQL databases, all within about two weeks time, I would be worn out (and if you noticed, all of these examples listed come from posts you've submitted within the last two weeks.)

I don't mind helping you, and I know there's a tone of people on this site who are eager to help you too, but my advice going forward would be to use your intensity towards mastering a single concept, rather than spreading yourself thin with trying to do it all at once.

That being said, here's an exercise for you regarding this last question: using the native Blitz commands for strings, such as Len(), Left(), Mid(), Right(), ect., I want you to come up with a demo on how to make a word wrapping system. Don't worry about implementing this into your game yet, that's too complex. You can do that later. For now, just focus on being able to post some code here which can run by itself, no extra media required. This demo should include:

1. A texting system, where when the line reaches either the end of the screen or the end of a space you've defined, the text will word-wrap onto the next line. This can be done entirely with Blitz, and I know this because I have a system like that myself that I wrote not that long ago.

2. An easy to implement system. What this means is that I want the majority of this program to be contained within a single function, and, if possible, don't use any global variables. If you do this right, the only thing that other programmers would have to do is copy and paste this function into their game, make a string at some point, and call this function to make it word wrap.

I know that you've got the stuff to do this yourself, and if you're up for the challenge, take a stab at it. If you need help getting started, let me know and I'll give you some pseudo for layout or help you with the tough problems.


Guy Fawkes(Posted 2011) [#11]
I'll try, but I doubt I would be any good at this :/


Guy Fawkes(Posted 2011) [#12]
Because, I mean. man. I LOVE this forum. I have a forum addiction, actually :P

The people on this site are AMAZING! =D


Guy Fawkes(Posted 2011) [#13]
Here's my code, but it's HORRIBLE! *insert sadface here*




Adam Novagen(Posted 2011) [#14]
Not really horrible, just nowhere near enough. Time to start practicing planning and thought over copy-paste-editing.

Q: What IS word wrapping?

Let's hear your version of what word wrapping is, and what it needs to do. Break it down as much s you can; this will actually be for your benefit more than ours, just go with me on this. ;)


Guy Fawkes(Posted 2011) [#15]
Word Wrap: Wraps text in a certain area up to a certain width, if it reaches that width, it goes to the next line.


Adam Novagen(Posted 2011) [#16]
if it reaches that width, it goes to the next line.

Alright, so far so good. So you now know two things:

1. You need to know how long each line should be.
2. You need an If statement - since you actually said "if" yourself - to check IF the line is longer than the length you want.

Start with those basic elements, and alter your code so that it only displays the letters of Name$ that fall within the width limit. Hint: you can't do it taking Name$ as a whole, you'll need to add a letter at a time until it reaches the point of "too long."


Guy Fawkes(Posted 2011) [#17]
how do i use timers for this?


Adam Novagen(Posted 2011) [#18]
Not sure what you mean by timers, or rather not quite sure how you want to use them in this case. Just post the string-too-long testing code when you've got that going, we'll take it from there.

EDIT: Dinner now, next reply will probably be quite delayed XD

Last edited 2011


Who was John Galt?(Posted 2011) [#19]
Okay, I thought this guy was just lazy, but "how do I use timers for this?" The guy is a troll.


Guy Fawkes(Posted 2011) [#20]
I'm not a troll. wtf is ur problem?


Guy Fawkes(Posted 2011) [#21]
i do NOT appreciate being called something im not.


stayne(Posted 2011) [#22]
Rez, it is obvious that programming isn't your thing. I know it's hard to accept because it is so much fun but sometimes you just need to give something up and find something else that you are passionate about. I tried programming for a long time and struggled to understand every line of code (take a look at my older posts...I have been here for 6+ years). I FINALLY accepted the fact that I just didn't have what it took and I moved on. Life is better without the constant stream of code running through my head. Some nights I couldn't even sleep because of it, wondering why I didn't "get it" as so many others do such as Stevie G.

It doesn't mean you aren't smart at all, it just means the logic of programming doesn't agree with your style of thinking. If it's a pride thing then you are going about real life the wrong way. Maybe try 3D modeling, texture work, sfx, music...there are so many other things to do besides code. There are plenty of coders out there (some would say too many). I see you holding back frustration in every post. Please try something else for your sake or you are just going to suffer more and more every day.

Last edited 2011


Guy Fawkes(Posted 2011) [#23]
im not quitting. NO one can make me


Yasha(Posted 2011) [#24]
im not quitting. NO one can make me


Hmm, someone's had too much exposure to all that 80s "determination and self-belief achieves anything" nonsense.

Believe it or not the desire to not give up is pretty common. But the thing is, it's not always helpful if it impacts your ability to correctly judge what you're doing, what you need to do and whether you can actually do it. There is no shame in admitting you're not ready and trying a different path.

From here, it looks a lot like you're trying to get over a metaphorical concrete wall that is your difficulty with your project. You run, you jump, you scrabble, you fall; and you can't reach the top of the wall. So you jump again. But in all the determination to climb over it and not listening to people telling you to stop damaging your hands on the concrete, you are ignoring the door six feet to your left.

In other words, you don't seem to be ready for a massive game project yet. The problems you post seem very much to be "what I need done in order to finish this specific game" rather than "how can I get better at programming". Which is why you're not understanding things; nothing is building on your existing knowledge and that means it's not contributing to it.

So if you want to get better at programming, you have to be willing to learn programming, not try to knock out a specific product and hope the skill just osmoses into you along the way. It doesn't work like that.

This forum is full of people who are very happy to help you do both things, but I really don't think you'll have much success until you admit to yourself that you need to learn before you can build.


Ginger Tea(Posted 2011) [#25]
just as an aside, why would you want a word wrapped avatar name?
Are MMO players prone to realy long names displayed over their heads? Honest question, never played em and always kept my names short.

Myself I would turn off such features if I had to find my world view obstructed by names like "Mr David Michael Ecclesworth-Hingebottom III Esq" or "Lord Dark Overseer of the Nether Realm"

How long are you expecting the names to be if you need them word wrapped or are you just hedging your bets incase you do get long names like those, if thats the case, having "Mr David M..." displayed once it goes over your desired limit.

Edit:
After reading Yasha's post that wasn't here when I started typing, way back when, when blitz3D was new and we had an influx of people asking for makemyfps() code help, hardly any had actually programmed anything basic, let alone manage a head first jump into a large under taking as 3D FPSer, and the advice then as is always, start small and build up, there was a web article at the time called something like "from pacman to quake" the evolution of the first person shooter came from top down shooters of old and wolfenstien 3D was a top down shooter in game mechanics and level design, it was just the viewpoint that changed.
working from pacman and ghost AI to top down shooters (not side scrolling shootemups) whos names escape me at the moment, with similar enemy pathing AI you can then build up more complex games and then when the tech was there most had the game mechanics they required sussed and all was needed was the 3D coding.

Another similar evolution was pong to break out to space invaders.
What is break out (Akranoid) but pong vs a wall, what is space invaders but a moving wall that shoots back.

Baby steps and rehashing old games are always a good way of learning how code works, you know the game mechanics to tetris? think how you would move the blocks with the cursor keys or wsad, jiggle with old games and think about what makes them tick, think about how you want to remake it in blitz, look at the command reference and see which commands would be best to use, think of them like ingreedients to a cake, just cos you have a bag of cement handy, doesn't mean you should just throw anything and everything into the mix.

Last edited 2011


Rob the Great(Posted 2011) [#26]
A troll? lol, I don't think I've ever heard that insult before.


This forum is full of people who are very happy to help you do both things, but I really don't think you'll have much success until you admit to yourself that you need to learn before you can build.



Agreed. I can guarantee you that there is no programmer out there who was able to learning everything they know overnight. I've been a hobbyist programmer for over 7 years now, and I still don't feel confident enough with my skills to try a harder language, like C++ and whatnot. We all had to start somewhere, and the best way this forum can help you is if you're willing to learn from the beginning. Ideally, when you look through the forum, you should be able to look at someone else's code and have a general sense of what the outcome will be. When you hit that point, that's when these forums are going to have the biggest impact on you. Before that point, I doubt they serve a purpose, because what we will suggest will be too complicated if you don't understand the basics.

Don't let this discourage you. Instead of trying to learn it all at once, how about taking a very slow pace and getting to know 2D programming like the back of your hand? Do like Ginger Tea suggests, and look at the old school games and see how they were made. Maneesh Sethi's "Game Programming for Teens" does that very thing, starting with being able to print "Hello World" and moving all the way up to designing a space invaders game. Yes, it's all in 2D and may not be the most exciting game you've ever played, but doing this will lay down the groundwork for you to move on to bigger and better games.

And, if you still don't feel like you understand programming, then look into design. I am a horrific designer. I kid you not, I think I can maybe make a sphere in Milkshape and, on a good day, I can texture it. So, I quickly learned that design and modelling was not my forte. But that's OK, because I found other aspects to game design that I was good at.

To answer your question about timers, I would certainly NOT consider adding a timer to your code above until you were positive the word wrapper did exactly what it should be doing. Right now, the code you have isn't a word wrapper, but more or less a text scroller, increasing the letters being texted in every loop. Only, you don't see the result because Blitz cycles through all of them with the For...Next loop without flipping. But to use a timer for anything (which I assume you mean a Millisecond timer, not an actual timer like CreateTimer()), you simply create a variable, store Millisecs() to it when you want to start timing, then compare the new Millisecs() value to the stored variable and the actual time you want to pass. Code could look like:
time = Millisecs()

While Not KeyDown(1)

   If Millisecs() >= time + 1000 ;1 second has passed
      Print "More than 1 second has passed"
   EndIf

Wend


This is useful to control the timing of your game, but like I said before, this isn't related to word wrapping, and don't use text scrolling until you've got the word wrapping down.


Who was John Galt?(Posted 2011) [#27]
In other words, you don't seem to be ready for a massive game project yet. The problems you post seem very much to be "what I need done in order to finish this specific game" rather than "how can I get better at programming". Which is why you're not understanding things; nothing is building on your existing knowledge and that means it's not contributing to it.
Exactly this. The guy will not learn because at no point does he attempt to learn. Even the 'I learned my lesson' thread is a joke as he's still employing the exact same modus operandi as before his break.


Rob the Great(Posted 2011) [#28]
Ah, I suddenly understand what that thread was about. Does he have a history of this?


Who was John Galt?(Posted 2011) [#29]
Yes, Rob. If you have 5 minutes to waste, need a laugh and are not offended by naughty words, see for yourself.

http://www.blitzbasic.com/Community/posts.php?topic=89521#1016867


Rob the Great(Posted 2011) [#30]
Haha, wow, that was entertaining.

On a somewhat unrelated note, has anyone noticed that you appear to be shouting at the top of your lungs WHEN YOU CAPITALIZE EVERYTHING? YOU CAN EVEN ADD MORE EMPHASIS BY ADDING ADDITIONAL PUNCTUATION MARKS AT THE END OF A SENTENCE!!!!!

Oh, I need more laughs like that in my life.


Who was John Galt?(Posted 2011) [#31]
Hahaha!

GOOD OBSERVATION ROB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Guy Fawkes(Posted 2011) [#32]
It looks like YOUR the troll, John Galt -.- Plain and simple. Thank you for the examples everyone, but it looks like this thread is closed due to the simple fact that John Galt likes to troll :)


.rIKmAN.(Posted 2011) [#33]
Rez, stop being a muppet and start reading - nobody can help you if you don't help yourself...


Yasha(Posted 2011) [#34]
It's always worth a shot suggesting this, so here goes - the closest thing I know to a "fast track" to getting good at programming:

The Structure and Interpretation of Computer Programs, by Abelson and Sussman (free to read, PDF copies are around somewhere)

This is considered by a very large number of advanced CS people to be the finest textbook on programming and computer science ever written. It's one of the few books out there that both teaches programming in general, rather than how to use a given language, while also keeping the hard maths to a minimum so as to stay accessible to the general reader.

That's not to say it's an easy book. It used to be the intro textbook for the Computer Science course at MIT. There was a high dropout rate. But perhaps this will appeal to your sense of competition and determination.

You'll also note: the book uses a language wildly different from Blitz. This is good: it means you have to learn principles for real, and absolutely cannot simply try to pick up code snippets without understanding them. And it won't teach you anything at all about game design, which is a completely separate topic that technically doesn't even have to involve programming. Again, this is good, because it means focus.

The book is quite long, and might be a little daunting. If you complete even the first section ("Building Abstractions with Procedures") and understand it properly (can't emphasize enough: do all the exercises!), you'd already be an above-average programmer (that's only ~85 pages out of ~600!).


The compiler they recommend to do the exercises with is a bit difficult to setup and use: SISC provides exactly the same language and you can use it right in your browser. Gambit is another good one when you need a downloadable version (handy once you start writing longer pieces and want to save your files).


Are you tough enough?

Last edited 2011


Adam Novagen(Posted 2011) [#35]
*gives Yasha an enormous glomp hug*

I LOVE THIS FORUM. I think this here might be the best thing EVER. Damned if I'm not going to take this book up in my spare time! :D


Ross C(Posted 2011) [#36]
Yeah, nice one Yasha. I'll give that a read :)


Graythe(Posted 2011) [#37]
Wow, reminds me of

http://www.youtube.com/watch?v=96-nPOfBPMg


Ross C(Posted 2011) [#38]
Oh, btw Rez check out your other thread in the blitz3d part of the forum. I posted my new text wrap function. Take as it is :)


Guy Fawkes(Posted 2011) [#39]
Thanks Ross! :) The ONLY problem with the text code u made me, is that I need to choose between auto messages coming up (by touching the NPC, or activating it automatically if a variable = 1), or the normal keypress (like u had before) :) Other than that, it's the best damn code u've ever helped me with :)