How to display images in code?

Senfgurke

Villager
Member
Joined
Dec 29, 2018
Messages
5
Reaction score
0
First Language
German
Primarily Uses
RMMV
Hi there,
I would consider myself a relatively seasoned JS-Scripter and also collected some experience in RPGMaker XP in my younger years. Right now I'm trying to make a custom battle system with cards.
For a first Proof-Of-Concept my idea was to use skills as the cards and in the note tag of the skill I would reference the image for the card to be used.
e.g. <image: 0001.png>

Right now I have an array of IDs (the IDs of the skills) that represents my deck and now I want to show the corresponding pictures on my battlescreen.
Whats the best way to do this? I have a custom folder full of the card images.


What I have so far:
A custom loadCard function
Code:
   ImageManager.loadCard = function(filename, hue) {
        return this.loadBitmap('img/cards/', filename, hue, false);
    };
My custom createCards function that I wrote for the Spriteset_Battle.
Code:
 Spriteset_Battle.prototype.createCards = function(){
        var card = new Sprite_Picture();
        card.bitmap = ImageManager.loadCard('0001');
        card.x=1;
        card.y=1;
        card._width=200;
        card._height=200;
        this._battleField.addChild(card);
        console.log("battlefield",this._battleField);
    }
The function gets called, I get the console log, however I see no picture. Is this the right way? Should I use Sprite_Picture? Is something important missing?

What I also want to do is add the pictures to the battlefield as a child so they get updated constantly. Is this correct?

Thanks for any help,
cheers :)
 

Senfgurke

Villager
Member
Joined
Dec 29, 2018
Messages
5
Reaction score
0
First Language
German
Primarily Uses
RMMV
Also i think i posted this in the wrong forum. I'm guessing this should go into learning JavaScript? I'm not sure. Im sorry however, if this is the wrong forum.
 

FleshToDust

I make youtube videos
Veteran
Joined
Jul 10, 2017
Messages
756
Reaction score
2,869
First Language
English
Primarily Uses
RMMV
I don't know about the js code stuff but I made a card system and I did it with events.
You can do a draw phase for example and say

If DrawCardRandom = 1
Variable HandZone1 = 1

That will change your hand zone to 1.
You'll then have a parallel process event that will say

If HandZone1 = 1
Show Picture MonsterCard1 in x and y coordinates

That should show you the card on screen.

If you then want to play that card and put it on the field you'll click on HandZone1 and it will say

If HandZone1 = 1 Show Choices
Play: HandZone1 = 0|FieldZone1 = 1
Back

This will remove the card from your hand and put it on the field. The picture in your hand will disappear.
In order for it to show up on the field though what you'll need to do is go into your parallel process event that controls all the pictures in your game and say

If FieldZone1 = 1
Show Picture: MonsterCard1

I hope this helps.
 

DrDhoom

Monkey Needs a Hug
Veteran
Joined
Mar 16, 2012
Messages
154
Reaction score
157
First Language
Indonesian
Primarily Uses
N/A
Don't use Sprite_Picture, instead use regular Sprite object. Or even better, create your own sprite object with Sprite as the prototype.
Example:
Code:
function Sprite_Card() {
    this.initialize.apply(this, arguments);
}

Sprite_Card.prototype = Object.create(Sprite.prototype);
Sprite_Card.prototype.constructor = Sprite_Card;

Sprite_Card.prototype.initialize = function (bitmapName) {
    Sprite.prototype.initialize.call(this);   
    this.bitmap = ImageManager.loadCard(bitmapName);
    this.x = 1;
    this.y = 1;
};
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Senfgurke I think you're right, Learning JavaScript would probably be better.

Moving this.
 

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
I don't know about the js code stuff but I made a card system and I did it with events.
You can do a draw phase for example and say

If DrawCardRandom = 1
Variable HandZone1 = 1

That will change your hand zone to 1.
You'll then have a parallel process event that will say

If HandZone1 = 1
Show Picture MonsterCard1 in x and y coordinates

That should show you the card on screen.

If you then want to play that card and put it on the field you'll click on HandZone1 and it will say

If HandZone1 = 1 Show Choices
Play: HandZone1 = 0|FieldZone1 = 1
Back

This will remove the card from your hand and put it on the field. The picture in your hand will disappear.
In order for it to show up on the field though what you'll need to do is go into your parallel process event that controls all the pictures in your game and say

If FieldZone1 = 1
Show Picture: MonsterCard1

I hope this helps.
Dude, this is all eventing?! Damn, that is really impressive.
 

Senfgurke

Villager
Member
Joined
Dec 29, 2018
Messages
5
Reaction score
0
First Language
German
Primarily Uses
RMMV
I don't know about the js code stuff but I made a card system and I did it with events.
You can do a draw phase for example and say

If DrawCardRandom = 1
Variable HandZone1 = 1

That will change your hand zone to 1.
You'll then have a parallel process event that will say

If HandZone1 = 1
Show Picture MonsterCard1 in x and y coordinates

That should show you the card on screen.

If you then want to play that card and put it on the field you'll click on HandZone1 and it will say

If HandZone1 = 1 Show Choices
Play: HandZone1 = 0|FieldZone1 = 1
Back

This will remove the card from your hand and put it on the field. The picture in your hand will disappear.
In order for it to show up on the field though what you'll need to do is go into your parallel process event that controls all the pictures in your game and say

If FieldZone1 = 1
Show Picture: MonsterCard1

I hope this helps.
Thank you for your reply FleshToDust, thats really impressive! However, I think it would be quite a tedious task for me to implement my complete battle system event based. Where I was stuck was how I could get my graphic to show on the screen, in an event based system this would simply be the show Picture command.

Don't use Sprite_Picture, instead use regular Sprite object. Or even better, create your own sprite object with Sprite as the prototype.
Example:
Code:
function Sprite_Card() {
    this.initialize.apply(this, arguments);
}

Sprite_Card.prototype = Object.create(Sprite.prototype);
Sprite_Card.prototype.constructor = Sprite_Card;

Sprite_Card.prototype.initialize = function (bitmapName) {
    Sprite.prototype.initialize.call(this);  
    this.bitmap = ImageManager.loadCard(bitmapName);
    this.x = 1;
    this.y = 1;
};
Thank you DrDhoom, I now have a picture! Using a custom sprite class for the Cards seems logical. Thank you very much! I hope everything works out how I think it will, but at least now I'm not stuck on showing the cards. :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top